Concatenation of LPWSTR strings

后端 未结 3 1809
梦谈多话
梦谈多话 2020-12-18 22:52

In Visual C++, I have a

LPWSTR mystring;

which is already defined somewhere else in the code.

I want to create a new LPWSTR contain

相关标签:
3条回答
  • 2020-12-18 23:32

    The C++ way:

    std::wstring mywstring(mystring);
    std::wstring concatted_stdstr = L"hello " + mywstring + L" blah";
    LPCWSTR concatted = concatted_stdstr.c_str();
    
    0 讨论(0)
  • 2020-12-18 23:33
    std::wstring mystring_w(mystring);
    std::wstring out_w = L"hello " + mystring_w + L" blablabla";
    LPWSTR out = const_cast<LPWSTR>(out_w.c_str());
    

    'out' is a LPWSTR wrapper for 'out_w'. So as long as 'out_w' is in scope it will be good to use. Also you don't need to delete 'out' as it's is binded to 'out_w' lifecycle.

    This is pretty much the same answer 'user529758' gave, but with 'chris' proposed modification.

    0 讨论(0)
  • 2020-12-18 23:36

    You can use StringCchCatW function

    0 讨论(0)
提交回复
热议问题