Author Topic: gnu compiler : ostream_iterator problem  (Read 4836 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
gnu compiler : ostream_iterator problem
« on: November 15, 2005, 09:47:42 pm »
Anyone aware of the following problem with the gnu compiler (or just the mingw port) ??

The following simple code does not compile :

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   vector<int> coll;
   coll.push_back(10);
   coll.push_back(20);
   coll.push_back(30);
   copy(coll.begin(), coll.end(), ostream_iterator<int>(cout, "\n"));
   return 0;
} // end of main

I get :

main.cpp: In function `int main()':
main.cpp:13: error: `ostream_iterator' undeclared (first use this function)
main.cpp:13: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:13: error: expected primary-expression before "int"
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings
 

I does build with M$ VC 2005, and according tothe book The C++ Standard Library (Josuttis), page 107, this is correct code.

IS there some part not supported by either :
 - GNU C++ compiler
 - MingW port


kind regards,
Lieven

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: gnu compiler : ostream_iterator problem
« Reply #1 on: November 15, 2005, 09:53:24 pm »
also with Digital Mars I get the error :

dmc.exe -mn -c       -I"C:\dm\stlport\stlport" -I"C:\dm\include" -o.Marsobjs\main.o main.cpp
   copy(coll.begin(), coll.end(), ostream_iterator<int>(cout, "\n"));
                                                  ^
main.cpp(13) : Error: undefined identifier 'ostream_iterator'
C:\dm\stlport\stlport\stl/_algobase.h(139) : Error: pointer required before '->', '->*' or after '*'
Had: int
   return 0;
        ^
main.cpp(14) : Error: ';' expected following declaration of struct member
--- errorlevel 1
Process terminated with status 1 (0 minutes, 3 seconds)
3 errors, 0 warnings

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: gnu compiler : ostream_iterator problem
« Reply #2 on: November 15, 2005, 09:57:47 pm »
Add #include <iterator> and it 'll work ;)
Be patient!
This bug will be fixed soon...

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: gnu compiler : ostream_iterator problem
« Reply #3 on: November 15, 2005, 09:59:28 pm »
Yiannis, you're the greatest.
Thanks,
Lieven.