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 17:59:46
|
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 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.
----- Original Message -----
From: "Ioannis Vranos" <no...@ya...>
To: <dev...@li...>
Sent: Friday, September 21, 2001 9:23 AM
Subject: RE: [Dev-C++] Integer to std::string?
> I do not know string's member functions yet, but i know C well and you
> can use sprintf() to convert a number to a C string, so:
>
> #include <cstdio>
> #include <iostream>
> #include <string>
>
> int main()
> {
> using namespace std;
>
> char array[100];
>
> sprintf(array, "This is a string with numbers, %d is integer, %f is
> float", 2, 5.5);
>
> string s=array;
>
> cout<<s<<endl;
> }
>
>
> Ioannis
>
> * Ioannis Vranos
> * Programming pages: http://www.noicys.f2s.com
> * Alternative URL: http://run.to/noicys
|