C++: vector<pair<int,int>>v(size); showing 0 as values when I am trying to print out the values, but when the vector size is not declared it is showing correct output? Why so?
For example:
int x;
cin>>x;
vector<pair<int,int>>v(x); //Size declared.
for(int i=0;i<x;i++){
int p,q;
cin>>p>>q;
v.push_back(make_pair(p,q));
}
But when I am trying to print the values, it is printing 0 only.
I/P->
3
1 2
3 4
5 6
O/P->
0 0
0 0
0 0
But when I don't declare the size of the vector it prints the output without any error, why is that? i.e
int x;
cin>>x;
vector<pair<int,int>>v; //Size is not declared.
for(int i=0;i<x;i++){
int p,q;
cin>>p>>q;
v.push_back(make_pair(p,q));
}
I/P->
3
1 2
3 4
5 6
O/P->
1 2
3 4
5 6
It shows the correct output. Why is that?