convert int to wstring

30,925

Solution 1

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.

Solution 2

    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.

Share:
30,925
l3utterfly
Author by

l3utterfly

Updated on January 12, 2021

Comments

  • l3utterfly
    l3utterfly over 3 years

    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.

  • Karthik T
    Karthik T about 11 years
    @WhozCraig me neither, was trying to find the wstring page
  • l3utterfly
    l3utterfly about 11 years
    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.
  • Dave
    Dave almost 7 years
    no wonder the coding world is so messed up, half implemented standards shakes head in disgust at the IT industry