Jump to content
  • Advertisement
Sign in to follow this  
Gink

Istream iterator doesnt work in dev-cpp?

This topic is 4802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

vector<string> coll;

copy (istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(coll)); 
generates errors, anyone know a fix to this?

Share this post


Link to post
Share on other sites
Advertisement
Interesting. That is an example from a book on the STL.

Did you include all the header files?

Kuphryn

Share this post


Link to post
Share on other sites
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++.

Share this post


Link to post
Share on other sites
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> //copy
using 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!

Share this post


Link to post
Share on other sites
The book listed 4 includes so I didnt think he was going to leave out <iterator>, that explains it, thx

Share this post


Link to post
Share on other sites
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());

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!