convert int to string
-
Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita
-
Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita
One way:
ostringstream ss; ss << "The number is " << 42; string s = ss.str();
There are many ways. You didn't really explain the context properly so I assumed that by "string" you meant STL strings. Note that the above code assumes that you've included<string>
and<sstream>
and have putusing namespace std;
somewhere appropriate. Steve -
Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita
have a look at atoi() and itoa() For me CAR is Challenge, Achievement and Recognition. ;-) _AnShUmAn_
-
One way:
ostringstream ss; ss << "The number is " << 42; string s = ss.str();
There are many ways. You didn't really explain the context properly so I assumed that by "string" you meant STL strings. Note that the above code assumes that you've included<string>
and<sstream>
and have putusing namespace std;
somewhere appropriate. Stevehi, Thanks for ur reply. Actually i am storing picture number in int picno; I need to convert this picture number to string. can i able to convert? sunita
-
hi, Thanks for ur reply. Actually i am storing picture number in int picno; I need to convert this picture number to string. can i able to convert? sunita
Almost exactly the same as the previous example:
ostringstream ss; ss << picno; string s = ss.str();
Steve -
Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita
sunita ramesh wrote:
How to convert int to string ,string to int in vc++.
CString::Format, wsprintf, _ttoi
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita
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 intint x=0; CString s="12345"; x = atoi(s); // x= 12345 as integer
Osama E. Adly -
Hi all, Please any one tell me How to convert int to string ,string to int in vc++. thanks sunita