ostream_iterator

E

Evyn

Hi,

Can someone tell me why I always get an error like "`ostream_iterator'
undeclared (first use this function) " when using ostream_iterator. I
have for example tried the following code taken from
http://www.camtp.uni-mb.si/books/Thinking-in-C++/Chapter04.html :

//: C04:Intset.cpp
// Simple use of STL set
#include <set>
#include <iostream>
using namespace std;

int main() {
set<int> intset;
for(int i = 0; i < 25; i++)
for(int j = 0; j < 10; j++)
// Try to insert multiple copies:
intset.insert(j);
// Print to output:
copy(intset.begin(), intset.end(),

TIA
ostream_iterator<int>(cout, "\n"));
} ///:~
 
M

Mike Wahler

Evyn said:
Hi,

Can someone tell me why I always get an error like "`ostream_iterator'
undeclared (first use this function) " when using ostream_iterator. I
have for example tried the following code taken from
http://www.camtp.uni-mb.si/books/Thinking-in-C++/Chapter04.html :

You're missing two headers:
<algorithm> (for std::copy)
<iterator> (for std::eek:stream_iterator)

Did Bruce really leave those out of his code?
I'm surprised, his code is usually fairly correct.
I suggest you check his actually web site
(http://mindview.net/Books/TICPP/ThinkingInCPP2e.html),
maybe you have an older version of his book from before
corrections were made.
//: C04:Intset.cpp
// Simple use of STL set
#include <set>
#include <iostream>
using namespace std;

int main() {
set<int> intset;
for(int i = 0; i < 25; i++)
for(int j = 0; j < 10; j++)
// Try to insert multiple copies:
intset.insert(j);
// Print to output:
copy(intset.begin(), intset.end(),

TIA
ostream_iterator<int>(cout, "\n"));
} ///:~

-Mike
 
B

BobR

Mike said:
You're missing two headers:
<algorithm> (for std::copy)
<iterator> (for std::eek:stream_iterator)

Did Bruce really leave those out of his code?
I'm surprised, his code is usually fairly correct.
I suggest you check his actually web site
(http://mindview.net/Books/TICPP/ThinkingInCPP2e.html),
maybe you have an older version of his book from before
corrections were made.




-Mike

I think you were right about an old version. It's chap 7 in final (chap
4 is "iostreams").

//: C07:Intset.cpp
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.

Bob R
Povrookie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top