14

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.

2 Answers 2

52

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.

Sign up to request clarification or add additional context in comments.

3 Comments

@WhozCraig me neither, was trying to find the wstring page
Exactly what I'm looking for. The answer couldn't be better. I didn't even know this was available. Nothing showed up when I googled my question.
no wonder the coding world is so messed up, half implemented standards shakes head in disgust at the IT industry
3
 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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.