RE: [Dev-C++] Integer to std::string?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2001-09-21 07:22:15
|
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
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Jason Hardman
> Sent: Friday, September 21, 2001 5:31 AM
> To: Dev-C++
> Subject: [Dev-C++] Integer to std::string?
>
>
> Hi,
>
> I'm a bit rusty in my C++ and I just cannot seem to find a
> way of initialising a std::string with an integer value.
> While I can write a function to do it quite easily I had
> thought that there was a either a standard function or member
> of string that would do it, but I can't find one. I might be
> missing something with being tired of course. I know in
> future I will want to be doing similar with float's too, and
> I hope there is an easy way of doing that. I don't want to
> have to reinvent the wheel if I can avoid it.
>
> I remember with AnsiString in BCB or (or Delphi) would take
> it as a constructor argument, but std::string doesn't seem to
> have that ability.
>
> Thanx for any help, Jason.
>
>
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|