errorCode:copy(sentence.begin(),sentence.end(), ostream_iterator<string>(cout," ")); cout << endl;
26 C:\Dev-Cpp\vector1\main.cpp
`ostream_iterator' undeclared (first use this function)
I took this example directly from a book and do not know why this line gives me problems. Can anyone help?
I'm using Dev_Cpp ver.4.9.8
From the error code I guess this iterator is not "included"
Here is the entire example:
Code:#include <iostream> #include <vector> #include <string> #include <algorithm> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { //create an empty vector for strings vector<string> sentence; //reserve memory for 5 elements to avoid reallocation sentence.reserve(5); //append some elements sentence.push_back("Hello, "); sentence.push_back("how"); sentence.push_back("are"); sentence.push_back("you"); sentence.push_back("?"); //print elements seperated with spaces copy(sentence.begin(),sentence.end(), ostream_iterator<string>(cout," ")); cout << endl; //print statistics cout << " max_size(): "<<sentence.max_size()<<endl; cout << " size(): "<<sentence.size()<<endl; cout << " capacity(): "<<sentence.capacity()<<endl; //swap second and fourth element swap(sentence[1],sentence[3]); //insert element "always" before element "?" sentence.insert(find(sentence.begin(),sentence.end(),"?"),"always"); //assign "!" to the last element sentence.back()="!"; //print elements seperated by spaces copy(sentence.begin(),sentence.end(), ostream_iterator<string>(cout," ")); cout << endl; //print statistics cout << " max_size(): "<<sentence.max_size()<<endl; cout << " size(): "<<sentence.size()<<endl; cout << " capacity(): "<<sentence.capacity()<<endl; system("PAUSE"); return 0; }



LinkBack URL
About LinkBacks


