POV-Ray : Newsgroups : povray.off-topic : My first C++ program : Re: My first C++ program Server Time
30 Sep 2024 21:29:09 EDT (-0400)
  Re: My first C++ program  
From: Nicolas Alvarez
Date: 19 Sep 2008 19:02:40
Message: <48d42f90@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.