>>>>> ">>" == Chris Mantoulidis <cm****@yahoo.c om> writes:
Hello all... I get an error message for the following program by the
compiler:
#include <iostream>
#include <string>
using namespace std;
ostream_iterato r<string> oo(cout);
int main()
{
*oo = "Hello ";
++oo;
*oo = "world!\n";
return 0;
}
the error says: "ostream_iterat or is used as a type, but is not
defined as a type."... What can I do to fix that?? I get the same
error with istream_iterato r...
cmad
Chris,
You need to include <iterator>!
ostream_iterato r exists as a unique template class as compared to the
iterators of STL containers which use traits to create their own nested
iterator classes, hence the scope resolution operator "::" when these are
instantiated, eg.
vector<int> my_vec(10);
// ...
vector<int>::it erator my_vec_itor = my_vec.begin();
.... you could even use a little more of the STL:
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<string> oo_vec;
oo_vec.push_bac k("Hello ");
oo_vec.push_bac k("world!\n") ;
copy(oo_vec.beg in(), oo_vec.end(), ostream_iterato r<string>(cout) );
return 0;
}
J.
--