Sunday, July 17, 2011

Stringstreams

* How does stringstream work?

Someone kind of explained it like, in cout it sends it to “standard out stream” or something, and using stringstream, you stream it into that instead.





stringstream a; int b=12;  a << b;




* How can it convert characters into int and such?





char a = '2';
int b;
stringstream c;
c << a;
c >> b;

//now b = 2




* How can you do this? I remember someone doing something similar like:





 stringstream d(a1) >> b;




But that doesn't work for me. Saying it expected a , or ; before >> token.


* Where does the garbage value come from?





    string a1="13", a2="25";
int b,c;
stringstream d;

d << a1;
d >> b;

d << a2;
d >>c;




c produces some garbage value, but where is that garbage value coming from?

I can understand a pointer pointing somewhere random, getting a garbage value, but this?

25 -> d -> c. I don't get it?

http://bit.ly/qwTuFT

No comments:

Post a Comment