about istream_iterator

Discussion in 'C++' started by ben, May 17, 2005.

  1. ben

    ben Guest

    Is istream_iterator<> and ostream_iterator<> supposed NOT to be included in
    <iostream>? The following example compiles in VC 7.1 but not with gcc 3.4.3

    #include <iostream>
    #include <deque>
    #include <algorithm>

    int main()
    {
    using namespace std;

    deque<int> ls;
    copy(istream_iterator<int>(cin), istream_iterator<int>(),
    back_inserter(ls));
    sort(ls.begin(), ls.end());
    copy(ls.begin(), ls.end(), ostream_iterator<int>(cout));
    return 0;
    }

    ben
     
    ben, May 17, 2005
    #1
    1. Advertising

  2. ben

    Mike Wahler Guest

    "ben" <> wrote in message
    news:4289f83a$0$10301$...
    > Is istream_iterator<> and ostream_iterator<> supposed NOT to be included
    > in
    > <iostream>?


    <iostream> is not prohibited from declaring those
    types, but neither is it required to do so.

    The header which will guarantee the declarations
    of 'istream_iterator' and 'ostream_iterator
    is <iterator>

    > The following example compiles in VC 7.1 but not with gcc 3.4.3
    >
    > #include <iostream>
    > #include <deque>
    > #include <algorithm>
    >
    > int main()
    > {
    > using namespace std;
    >
    > deque<int> ls;
    > copy(istream_iterator<int>(cin), istream_iterator<int>(),
    > back_inserter(ls));


    Also note that <iterator> must be included in order
    to guarantee declaration of 'back_inserter'.

    > sort(ls.begin(), ls.end());
    > copy(ls.begin(), ls.end(), ostream_iterator<int>(cout));
    > return 0;
    > }


    -Mike
     
    Mike Wahler, May 17, 2005
    #2
    1. Advertising

  3. ben

    ben Guest

    Thanks!

    ben


    "Mike Wahler" <> wrote in message
    news:Gtoie.3171$...
    > "ben" <> wrote in message
    > news:4289f83a$0$10301$...
    > > Is istream_iterator<> and ostream_iterator<> supposed NOT to be included
    > > in
    > > <iostream>?

    >
    > <iostream> is not prohibited from declaring those
    > types, but neither is it required to do so.
    >
    > The header which will guarantee the declarations
    > of 'istream_iterator' and 'ostream_iterator
    > is <iterator>
    >
    > > The following example compiles in VC 7.1 but not with gcc 3.4.3
    > >
    > > #include <iostream>
    > > #include <deque>
    > > #include <algorithm>
    > >
    > > int main()
    > > {
    > > using namespace std;
    > >
    > > deque<int> ls;
    > > copy(istream_iterator<int>(cin), istream_iterator<int>(),
    > > back_inserter(ls));

    >
    > Also note that <iterator> must be included in order
    > to guarantee declaration of 'back_inserter'.
    >
    > > sort(ls.begin(), ls.end());
    > > copy(ls.begin(), ls.end(), ostream_iterator<int>(cout));
    > > return 0;
    > > }

    >
    > -Mike
    >
    >
     
    ben, May 18, 2005
    #3
    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. Bill Rudolph

    istream_iterator question

    Bill Rudolph, Aug 14, 2003, in forum: C++
    Replies:
    4
    Views:
    549
    Bill Rudolph
    Aug 15, 2003
  2. Chris Mantoulidis
    Replies:
    2
    Views:
    414
  3. Alex Vinokur

    istream_iterator & copying files

    Alex Vinokur, Apr 19, 2004, in forum: C++
    Replies:
    10
    Views:
    1,237
    Alex Vinokur
    Apr 20, 2004
  4. NPC

    istream_iterator<>

    NPC, May 13, 2004, in forum: C++
    Replies:
    3
    Views:
    1,293
    tom_usenet
    May 14, 2004
  5. Alex Vinokur

    Copying with istream_iterator

    Alex Vinokur, Jul 21, 2004, in forum: C++
    Replies:
    9
    Views:
    584
    Alex Vinokur
    Jul 24, 2004
Loading...

Share This Page