ostream_iterator

Discussion in 'C++' started by Evyn, Jan 18, 2007.

  1. Evyn

    Evyn Guest

    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"));
    } ///:~
     
    Evyn, Jan 18, 2007
    #1
    1. Advertising

  2. Evyn

    Mike Wahler Guest

    "Evyn" <> wrote in message
    news:...
    > 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
     
    Mike Wahler, Jan 18, 2007
    #2
    1. Advertising

  3. Evyn

    Evyn Guest

    Ah - hah!!! Thanks!!! I will take a look at the original...

    Mike Wahler wrote:

    > 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.
     
    Evyn, Jan 18, 2007
    #3
  4. Evyn

    BobR Guest

    Mike Wahler wrote:
    > "Evyn" <> wrote in message
    >
    >>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

    >
    >
    > -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
     
    BobR, Jan 18, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aman

    ostream_iterator

    Aman, Oct 17, 2003, in forum: C++
    Replies:
    4
    Views:
    550
    Aman Angrish
    Oct 20, 2003
  2. Aman

    ostream_iterator

    Aman, Oct 17, 2003, in forum: C++
    Replies:
    0
    Views:
    313
  3. Chris Mantoulidis
    Replies:
    2
    Views:
    418
  4. Fraser Ross

    ostream_iterator from fstream

    Fraser Ross, Jul 13, 2004, in forum: C++
    Replies:
    12
    Views:
    2,422
    tom_usenet
    Jul 13, 2004
  5. Jeff
    Replies:
    8
    Views:
    3,547
    John Harrison
    Oct 5, 2004
Loading...

Share This Page