From: Jack on
How do I convert an integer to std::string?
Thanks
Jack


From: ramyasangeet@gmail.com on

Jack wrote:

> How do I convert an integer to std::string?
> Thanks
> Jack

Using MFC:
Convert int to string
int x=12345;
CString s; // s = "" (empty string)
s.Format("%d", x); // s = "12345" as string


Convert string to int
int x=0;
CString s="12345";
x = atoi(s); // x= 12345 as integer

Regards,
sangeet

From: Jack on

<ramyasangeet(a)gmail.com>
???????:1149495568.894697.301610(a)g10g2000cwb.googlegroups.com...
>
> Jack wrote:
>
>> How do I convert an integer to std::string?
>> Thanks
>> Jack
>
> Using MFC:
> Convert int to string
> int x=12345;
> CString s; // s = "" (empty string)
> s.Format("%d", x); // s = "12345" as string
>
Dear Sangeet,
Thanks for replying. But I regret to say that the target object type is
std::string rather than CString
std::string is standardised strings while CString is VC specific. Thanks
Jack

>
> Convert string to int
> int x=0;
> CString s="12345";
> x = atoi(s); // x= 12345 as integer
>
> Regards,
> sangeet
>


From: David Wilkinson on
ramyasangeet(a)gmail.com wrote:

> Jack wrote:
>
>
>>How do I convert an integer to std::string?
>>Thanks
>>Jack
>
>
> Using MFC:
> Convert int to string
> int x=12345;
> CString s; // s = "" (empty string)
> s.Format("%d", x); // s = "12345" as string
>
>
> Convert string to int
> int x=0;
> CString s="12345";
> x = atoi(s); // x= 12345 as integer
>
> Regards,
> sangeet
>

Jack:

Two possible methods:

int x = 0;
std::ostringstream os;
os << x;
std::string str = os.str();

or

int x = 0;
CString s;
s.Format("%d", x);
std::string str = s;

The boost librray also has some ways to do this.

David Wilkinson


From: Jack on

"David Wilkinson" <no-reply(a)effisols.com>
???????:ehwN7ZIiGHA.1612(a)TK2MSFTNGP04.phx.gbl...
> ramyasangeet(a)gmail.com wrote:
>
>> Jack wrote:
>>
>>
>>>How do I convert an integer to std::string?
>>>Thanks
>>>Jack
>>
>>
>> Using MFC:
>> Convert int to string
>> int x=12345;
>> CString s; // s = "" (empty string)
>> s.Format("%d", x); // s = "12345" as string
>>
>>
>> Convert string to int
>> int x=0;
>> CString s="12345";
>> x = atoi(s); // x= 12345 as integer
>> Regards,
>> sangeet
>>
>
> Jack:
>
> Two possible methods:
>
> int x = 0;
> std::ostringstream os;
> os << x;
> std::string str = os.str();
>
> or
>
> int x = 0;
> CString s;
> s.Format("%d", x);
> std::string str = s;
>
> The boost librray also has some ways to do this.
>
> David Wilkinson

Dear David,
It's all great, Thanks
Jack
>
>


 | 
Pages: 1
Prev: C++ Vs C#
Next: Help Using WinDBG