CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #4
    Join Date
    Oct 2008
    Posts
    1,456

    Re: cin and unknown number of integers

    Quote Originally Posted by tuli View Post
    I`d still love to know what i can do in such a case, except for parsing the input char by char.
    you can use getline and stringstream, or something like this to avoid excessive copying:

    Code:
    std::ifstream     file /* = ... */;
    std::vector<int>  ints;
    
    for( int val; file >> val; )
    {
    	ints.push_back( val );
    
    	if( file.peek() == '\n' )
    	{
    		do_something_on( ints );
    		ints.clear();
    	}
    }
    but there are also boost iostream, boost serialization, regex's, etc ... etc ...
    Last edited by superbonzo; December 2nd, 2012 at 11:39 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured