Re: [Dev-C++] Integer to std::string?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jason H. <jas...@bt...> - 2001-09-21 18:56:16
|
I've been looking at it myself to, and AFAICT there isn't standard string
support for converting from int. None of the string members listed in "C++
The Complete Reference" do it.
I have found an alternative way of doing what sprintf does, which is more
C++ like, by using an Array Based Output Stream. e.g.
#include <stdio.h>
#include <stdlib.h>
#include <strstream>
#include <iostream>
#include <string>
int main(int argc, char *argv[])
{
using namespace std;
char str[80];
ostrstream outs(str, sizeof(str));
string mystring;
outs << "An int " << 1024 << " or a float " << 1.234 << "." << ends;
mystring = str;
cout << mystring << endl;
system("PAUSE");
return 0;
}
I tested it just in case, and it seems to work OK, but is also a long winded
way of doing things.
Jason.
----- Original Message -----
From: "Ioannis Vranos" <no...@ya...>
To: <dev...@li...>
Sent: Friday, September 21, 2001 8:24 PM
Subject: RE: [Dev-C++] Integer to std::string?
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Jason Hardman
> Sent: Friday, September 21, 2001 7:59 PM
> To: dev...@li...
> Subject: Re: [Dev-C++] Integer to std::string?
>
>
> Thanks for that, I had forgotten about sprintf(). I have to
> say it's not an ideal solution. It seems odd that the idea of
> converting from numbers wasn't put into string. I think I may
I did not say that the idea of converting from numbers to string isn't
implemented in string, i said that i do not know it yet. :)
> still write some kind of function to convert "tostring",
> using sprintf is a more messy solution for my purpose.
>
> I'll be keeping my eye out for alternatives still though.
>
> Thanx, Jason.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.f2s.com
* Alternative URL: http://run.to/noicys
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|