convert integer value to string objcet?
-
Hi All, Is there any function in (standard) c++ that convert integer value to std:string object? Such as, ... int n = 123; string str_n = itos(n); ... or some efficient way? Thanks!
Yonggoo
-
lucy wrote:
I would use str_n.Format ("%d", n)
CString
needed, notstring
-
Hi All, Is there any function in (standard) c++ that convert integer value to std:string object? Such as, ... int n = 123; string str_n = itos(n); ... or some efficient way? Thanks!
Yonggoo
Yes, an ostringstream would do that. http://www.codeproject.com/vcpp/stl/ostringstream.asp[^]
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
lucy wrote:
str_n.Format ("%d", n)
I think that std::string has not such
Format
method. Maybe you're writing aboutCString
, Aren't you? By the way, I think the OP can use astringstream
object, for instance:std::stringstream ss;
std::string s;
ss << 5;
ss >> s;But I don't know how efficient this way is. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
I think you use of CString ;)
WhiteSky