Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > istream_iterator and ostream_iterator problem

Reply
Thread Tools

istream_iterator and ostream_iterator problem

 
 
Chris Mantoulidis
Guest
Posts: n/a
 
      12-14-2003
Hello all... I get an error message for the following program by the
compiler:

#include <iostream>
#include <string>

using namespace std;

ostream_iterator<string> oo(cout);

int main()
{
*oo = "Hello ";
++oo;
*oo = "world!\n";

return 0;
}

the error says: "ostream_iterator 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_iterator...

cmad
 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      12-14-2003
Chris Mantoulidis wrote in news:a8587dd9.0312132333.526171b8
@posting.google.com:

> Hello all... I get an error message for the following program by the
> compiler:
>
> #include <iostream>
> #include <string>
>


#include <iterator>

> using namespace std;
>
> ostream_iterator<string> oo(cout);
>
> int main()
> {
> *oo = "Hello ";
> ++oo;
> *oo = "world!\n";
>
> return 0;
> }
>
> the error says: "ostream_iterator 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_iterator...
>


std:stream_iterator is declared in <iterator>.

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
 
Reply With Quote
 
 
 
 
Jord
Guest
Posts: n/a
 
      12-15-2003
>>>>> ">>" == Chris Mantoulidis <(E-Mail Removed)> writes:

>>> Hello all... I get an error message for the following program by the
>>> compiler:


>>> #include <iostream>
>>> #include <string>
>>>
>>> using namespace std;
>>>
>>> ostream_iterator<string> oo(cout);
>>> int main()
>>> {
>>> *oo = "Hello ";
>>> ++oo;
>>> *oo = "world!\n";
>>> return 0;
>>> }


>>> the error says: "ostream_iterator 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_iterator...


>>> cmad


Chris,

You need to include <iterator>!

ostream_iterator 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>::iterator 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_back("Hello ");
oo_vec.push_back("world!\n");
copy(oo_vec.begin(), oo_vec.end(), ostream_iterator<string>(cout));

return 0;
}

J.
--
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stl copy and istream_iterator and operator >> persres@googlemail.com C++ 8 09-19-2011 10:19 PM
ostream_iterator and vector< pair<int, string> > subramanian100in@yahoo.com, India C++ 3 10-01-2007 08:35 AM
Problem with defining operator<< for std::ostream_iterator krzysztof.konopko@gmail.com C++ 5 05-30-2007 10:52 AM
problem facing while using ostream_iterator alzforu@yahoo.com C++ 2 11-13-2006 11:48 AM
How to resolve ADL(?) issue using std::copy and std::ostream_iterator Chris Johnson C++ 6 07-03-2006 01:55 AM



Advertisments