Istream iterator doesnt work in dev-cpp?

Started by
5 comments, last by snk_kid 18 years, 10 months ago

vector<string> coll;

copy (istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(coll)); 
generates errors, anyone know a fix to this?
Advertisement
Interesting. That is an example from a book on the STL.

Did you include all the header files?

Kuphryn
be nice if you gave us the exact errors...

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

This works with GCC with no warnings, so I'd imagine it should work with Dev-C++.

#include <iostream>#include <string>#include <vector>#include <iterator>#include <algorithm>int main() {  using namespace std;    vector<string> coll;  copy(istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(coll)); }


If not, you could try downloading a more recent version of MinGW. I have no idea what version comes with Dev-C++.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Allways include your actual errors.

This should compile:

#include <iostream> //cin#include <vector> //vector#include <iterator> //istream_iterator, back_inserter#include <string> //string#include <algorithm> //copyusing namespace std;int main ( void ) {    vector< string > coll;    copy( istream_iterator< string >( cin ) , istream_iterator< string >() , back_inserter( coll ) );}


Edit: beaten by smart_idiot with almost the exact same code [sob] [cry] [sad]. I can't even get my smiley codes right!
The book listed 4 includes so I didnt think he was going to leave out <iterator>, that explains it, thx
another alternative:

#include <iterator>#include <vector>#include <string>#include <iostream>int main() {   typedef std::istream_iterator<std::string> iss_itr;   std::vector<std::string> v((iss_itr(std::cin)), iss_itr());}

This topic is closed to new replies.

Advertisement