Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert int to wstring

I want to convert an integer value (int) to std::wstring. What is the best way to do this? I'm developing for windows phone so I would rather avoid using external libraries (such as boost::lexical_cast). I'm looking for something simple, preferably one line of code that just assigns the int to the wstring.

Any help would be appreciated.

like image 770
l3utterfly Avatar asked Feb 18 '13 05:02

l3utterfly


2 Answers

Are you looking for std::to_wstring

std::wstring to_wstring( int value );   (since C++11)

Converts a signed decimal integer to a wide string with the same content as what std::swprintf(buf, sz, L"%d", value) would produce for sufficiently large buf.

like image 165
Karthik T Avatar answered Sep 22 '22 14:09

Karthik T


    size_t myInteger = 10;
    std::wostringstream myStringStream;
    myStringStream<< L"myText" << myInteger;
    std::wstring concatenatedStr = myStringStream.str();

Conacatenating number to wstring.

In old C++ 98 Visual Studio 2010.

like image 38
Abhijeet Narvekar Avatar answered Sep 21 '22 14:09

Abhijeet Narvekar