Conversion from int to basic string
-
I think he was asking how to convert an integer into a std::string directly
-
If he do so we can pause him... ;) He is providing C:\> prompt... Just type "pause" command there... :) - NS -
-
hey, don't worry, i'm a pacific intergalactic traveler... my only purpose is to provide C/C++ knowledge around our universe ;)
-
Hi Friend, Is there any API which convert int(int a) to basic string(string b)? itoa can convert a(int) to char*(Char *c) and I can get b from c.However is there any other way? Thanks :)
Here's how I'd go about doing it:
ostringstream ss; ss << "PI = " << 3.14159265; string s = ss.str();
Includes you'll need: <string> <sstream> Assumes:using namespace std;
Steve -
hum, so i didn't understand your question... in MS-DOS,
C:\>
is the common prompt to tell that you are located on the root directory of the C: drive. thever
command displays the actual version on MS-DOS installed (or windows since WinNT4 - as it doesn't need dos anymore) if i still don't answer your question, please rephrase:^) -
Hi Friend, Is there any API which convert int(int a) to basic string(string b)? itoa can convert a(int) to char*(Char *c) and I can get b from c.However is there any other way? Thanks :)
itkid wrote:
Is there any API which convert int(int a) to basic string(string b)?
std::basic_string
is a template. You can't convert to it, but only to its instantiations e.g.std::string
orstd::wstring
That said, I would take a look at boost.orgs lexical cast[^] or format[^]. Free but peer-reviewed code. Some of it will be part of the next version of the C++-Standard.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.
-
Here's how I'd go about doing it:
ostringstream ss; ss << "PI = " << 3.14159265; string s = ss.str();
Includes you'll need: <string> <sstream> Assumes:using namespace std;
Steve -
Hi Friend, Is there any API which convert int(int a) to basic string(string b)? itoa can convert a(int) to char*(Char *c) and I can get b from c.However is there any other way? Thanks :)