-
Vector Error??
Ok I am getting an error with my cout statement for my vector problem. This problem doesn't look any different that any other problem that I have done- so maybe I am just loosing it =)
The error is
binary '<<' : no operator defined which takes a right-hand operand of type 'class std::vector<int,class std::allocator<int> >' (or there is no acceptable conversion)
My code is:
Code:
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main () {
vector <int> v1;
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);
v1.push_back(4);
v1.push_back(5);
v1.push_back(6);
v1.push_back(7);
v1.push_back(8);
//v1.insert(v1.begin()+4, 88);
//v1.insert(v1.begin()+6, 33);
cout << v1;
return 0;
}
Thanks!!!!!
-
added for and "[]" for accessing element. Dropped string header its not needed.
Code:
#include<iostream>
#include<vector>
using namespace std;
int main ()
{
vector <int> v1;
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);
v1.push_back(4);
v1.push_back(5);
v1.push_back(6);
v1.push_back(7);
v1.push_back(8);
//v1.insert(v1.begin()+4, 88);
//v1.insert(v1.begin()+6, 33);
for(int x=0; x<v1.size(); x++)
{
cout << v1[x] <<endl;
}
return 0;
}
-
Thanks for the help!! That makes sense now- you have to look at each spot in the vector and print it out!! Thanks again!!
-
No problem, happy coding!