stringstream

Hi, i read many threads about noskipws in stringstream, but i still don't know how to use it. I want to create string with few variables (int, char and string). Sadly, stringstream ends my chain when finds space. Could somebody correct my code?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <sstring>
#include <string>

int main(){
stringstream ss;
char * a = "something";
int b = 2;
string c = "test", d;

ss << a << b << c << "const text"; //i don't know how to use noskipws in this line
ss >> d;

cout << d;

}
Last edited on
What do you want as desired result? What do you expect variable 'd' to hold?
closed account (DSLq5Di1)
noskipws will do just that, but the extraction operators still use whitespace as a delimiter,

1
2
ss >> d  // d = "something2testconst"
   >> d; // d = "text" 

1
2
3
4
ss >> noskipws
   >> d  // d = "something2testconst"
   >> d  // d = " "
   >> d; // d = "text" 

I presume what you want is d = ss.str(); // d = "something2testconst text" .
Sorry for my distraction. I wanted to get exactly that what sloppy9 wrote. Thank you for answers :D
Topic archived. No new replies allowed.