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

Threaded View

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

    Re: Reading a file using istream_iterator

    <EDIT: uhm, the following is in reply to post#3, of course>

    yes, and I already explained why getline does not work with your code, it's because of the way you're initializing the stringstream. Consider the following:

    Code:
    std::istringstream iss( "text10\0text20\0text30\0text40\0text50\0text60\0" );
    
    int main()
    {
    	std::string buffer;
    
    	while( std::getline( iss, buffer, char() ) )
    	{
    		std::cout << buffer << std::endl;
    	}
    }
    this won't work, outputting "text10". But this:

    Code:
    char iss_buf[] = "text10\0text20\0text30\0text40\0text50\0text60\0";
    std::istringstream iss( std::string( iss_buf, sizeof(iss_buf) ) );
    
    int main()
    {
    	std::string buffer;
    
    	while( std::getline( iss, buffer, char() ) )
    	{
    		std::cout << buffer << std::endl;
    	}
    }
    works as expected.
    Last edited by superbonzo; January 17th, 2012 at 10:27 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