Thread: StringStreams

  1. #1
    Registered User
    Join Date
    Oct 2005
    Location
    Brasil
    Posts
    220

    StringStreams

    Code:
    /* string buf
    stringstream ss;
    int EmailBuf.ID;
    */
    buf = "RETR ";
    ss << EmailBuf.ID;
    ss >> buf;
    When i do this, the variable buf stays with the value "RETR ", it is like stringstream never existed.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    int main()
    {
    	std::string buf("RETR ");
    	std::stringstream ss;
    	int ID = 6;
    	
    	ss << ID;
    	ss >> buf;
    	std::cout << buf;
    	return 0;
    }
    /*
    My output
    6
    */
    Seams to be problem somethere else
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Oct 2005
    Location
    Brasil
    Posts
    220
    output should be RETR 6, but as i saw in your code it is ok, i will try some more in my program

  4. #4
    Registered User
    Join Date
    Oct 2005
    Location
    Brasil
    Posts
    220
    No way. Maybe seeing a litlle bit more of the code...
    Code:
    		stringstream ss;
    		buf = sock->ReceiveLine();
    		if (buf[0] == '.')
    			break;
    
    		Email EmailBuf;
    		ss << buf[0];
    		ss >> EmailBuf.ID;
    		index = EmailBuf.ID;
    		index--;
    
    		buf = "RETR ";
    		ss << buf;
    		ss << EmailBuf.ID;
    		ss >> buf;

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    becasuse the strignstream contains spaces you cannot use >> to read from it the whole string ( >> stops on the first space)
    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    int main()
    {
    	std::string buf("RETR ");
    	std::stringstream ss;
    	int ID = 6;
    	
    	ss << buf << ID;
    	buf = ss.str();
    	std::cout << buf;
    	return 0;
    }
    /*
    My output
    RETP 6
    */
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A problem with loops and Stringstreams
    By mintsmike in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2009, 11:08 AM
  2. stringstreams problem
    By Mostly Harmless in forum C++ Programming
    Replies: 1
    Last Post: 06-11-2007, 09:13 PM
  3. stringstreams
    By Victor4015 in forum C++ Programming
    Replies: 1
    Last Post: 11-16-2005, 05:01 PM
  4. stringstreams help i know you guys will know
    By sswaters in forum C++ Programming
    Replies: 7
    Last Post: 10-22-2005, 07:46 PM
  5. stringstreams
    By zach0616 in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2005, 06:15 PM