StringStreams

This is a discussion on StringStreams within the C++ Programming forums, part of the General Programming Boards category; Code: /* string buf stringstream ss; int EmailBuf.ID; */ buf = "RETR "; ss << EmailBuf.ID; ss >> buf; When ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    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
    */
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 04: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21