|
|
Invisible wrote:
>>> ...you mean, you can take a string and make a stream that will read from
>>> it? (Or, presumably, write to it, if you desire.)
>>
>> Correct. Or, more precisely, you can write to an ostringstream and then
>> get a regular string out of it (with the str() function).
>
> Ah - because a string is fixed-size once created?
No. std::string is mutable, and can change its size.
This is how you can convert numbers to/from strings:
int answer = 42;
std::ostringstream oss;
oss << answer;
//oss.str() returns a std::string containing "42".
-------------
int answer;
std::istringstream iss("42");
iss >> answer;
//answer now contains the number 42.
Post a reply to this message
|
|