The string header isn't declared
#include<string>
The scope of cout and endl needs to be mentioned
std::cout << *iter << std::endl
cout << vector<string>example << endl;
What you are suggesting to do here is like:
cout << int x << endl;
You can't cout a type, but even if it's...
1 2 3
|
vector<string> example;
cout << example << endl;
|
...it is still not possible. I don't know the nitty gritty of it, but basically vector is a class that does not support the << operator to print all its elements in such a direct fashion.
To print the vector contents, you can either use this way here, which is using iterators, use subscripts [] like arrays, or call the
at member.
1 2 3 4 5 6 7
|
vector<int> example {1,2,3,4,5,6, 7};
for (int x = 0; x != example.size(); ++x)
{
cout << example[x] << "- subscripting" << endl;
cout << example.at(x) << "- calling at member" << endl;
}
|
Edit: Despite that, using iterators is generally better when working with containers like vector (ie for printing, modifying the elements, etc.)