User forums > General (but related to Code::Blocks)
TDM-GCC 4.5 series (Latest: 4.5.2 - 2011-03-27)
stefanos_:
Hello TDragon.
I think I have found a bug. While I was working on a certain example from a book of mine, I have discovered a bug regards to istream_iterator.
The code I used is this:
--- Code: ---// ioiter1.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
int main()
{
using namespace std; // all symbols in std are global
vector<string> coll; // vector container for strings
/* read strings from the standard input up until the end of the data
* - copy from the 'input collection' cin, inserting into coll
*/
copy(istream_iterator<string>(cin), // start of source range
istream_iterator<string>(), // end of source range
back_inserter(coll)); // destination range
// sort elements in coll
sort(coll.begin(), coll.end());
/* output all elements
* - copy from coll to the 'output collection' cout
* - every string on its own line (separated by "\n")
*/
copy(coll.begin(), coll.end(), // source range
ostream_iterator<string>(cout, "\n")); // destination range
}
--- End code ---
A special thanks goes to Nicolai M. Josuttis, author of book Object-Oriented Programming in C++, for composing such an amazing book.
The error report by compiler is this:
C:\Projects\Josuttis_OOP\Chapter_03\17. IOiter1\ioiter1.cpp||In function 'int main()': |
C:\Projects\Josuttis_OOP\Chapter_03\17. IOiter1\ioiter1.cpp|16|error: 'istream_iterator' was not declared in this scope|
C:\Projects\Josuttis_OOP\Chapter_03\17. IOiter1\ioiter1.cpp|16|error: expected primary-expression before '>' token|
C:\Projects\Josuttis_OOP\Chapter_03\17. IOiter1\ioiter1.cpp|17|error: expected primary-expression before '>' token|
C:\Projects\Josuttis_OOP\Chapter_03\17. IOiter1\ioiter1.cpp|17|error: expected primary-expression before ')' token|
C:\Projects\Josuttis_OOP\Chapter_03\17. IOiter1\ioiter1.cpp|28|error: 'ostream_iterator' was not declared in this scope|
C:\Projects\Josuttis_OOP\Chapter_03\17. IOiter1\ioiter1.cpp|28|error: expected primary-expression before '>' token|
C:\Projects\Josuttis_OOP\Chapter_03\17. IOiter1\ioiter1.cpp|28|warning: left-hand operand of comma has no effect|
||=== Build finished: 6 errors, 1 warnings ===|
I have pastebin-ed the current code and asked for help from Freenode's #C++-basic and tested it on Codepad and compiled just fine.
Can you please test this code with your 4.5.0 version and provide me your feedback? That would be greatly appreciated.
I'm waiting for anyone's reply.
Regards,
stefanos_
oBFusCATed:
stefanos_: Have you tried to include <iterator> ?
In gcc 4.5.0 the standard conformance is improved and the c++ standard says (I think),
that if you use something from the std namespace you should include the header, where it has been defined.
killerbot:
istream_iterator --> you need to include <iterator>.
So the code is wrong. By the way, I somewhat remember that in Josuttis STL book (which is GREAT), there were also includes missing. So always be careful with book examples, because most of the time the author was focusing on something different and didn't most probably pay attention if all includes are OK (or ensure there are no memory leaks), they also copy paste from one example to another ;-)
stefanos_:
Thank you both for your replies.
I just found the book's errata file and indeed, a missing iterator header was causing the whole thing to fall apart.
Fortunately we always have the chance with trial and error to resolve dummy "issues" like this :D
Thanks for once again.
Andrej08:
Thanks a bunch, TDragon!
I've just compiled wxWidgets & CB 30 mins ago, with no issues. Good job on TDM!
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version