vector<string> coll;
copy (istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(coll));
generates errors, anyone know a fix to this?
Istream iterator doesnt work in dev-cpp?
Interesting. That is an example from a book on the STL.
Did you include all the header files?
Kuphryn
Did you include all the header files?
Kuphryn
This works with GCC with no warnings, so I'd imagine it should work with Dev-C++.
If not, you could try downloading a more recent version of MinGW. I have no idea what version comes 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++.
Allways include your actual errors.
This should compile:
Edit: beaten by smart_idiot with almost the exact same code [sob] [cry] [sad]. I can't even get my smiley codes right!
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
Popular Topics
Advertisement