Vector Range

Why this below program is printing from 1-12773 only ??
I have also changed the datatype to long, same result.

#include <bits/stdc++.h>
using namespace std;

int main() {
vector v;
int i;
for(i=0;i<100000;i++)
{
v.push_back(i);
}
for(i=0;i<v.size();i++)
{
cout<<v[i]<<endl;
}
return 0;
}

2nd line:
vector<int>v;

You have not written data type for vector. How your program got compiled with this error?

2 Likes

Please format your code - the forum software has mangled it and it won’t compile! :slight_smile:

4 Likes

Mate, I have given the datatype in the vector. While copy pasting it in discussion page, the datatype got erased.

This is still not working Bro.

Hey, @abhishek_1401 you said you had mentioned the data type of the vector, so I tested it and it worked just fine on my machine.
Please check again that your code is same as-

#include <bits/stdc++.h>
using namespace std;

int main() {
vector<int> v;
int i;
for(i=0;i<100000;i++)
{
v.push_back(i);
}
for(i=0;i<v.size();i++)
{
cout<<v[i]<<endl;
}
return 0;
}

Misunderstandings like this wouldn’t happen if you just formatted your code.

1 Like