LPWSTR字符串的连接

Bas*_*asj 10 c++ string winapi concatenation string-concatenation

在Visual C++中,我有一个

LPWSTR mystring;
Run Code Online (Sandbox Code Playgroud)

已在代码中的其他位置定义.

我想创建一个新的LPWSTR,其中包含:

"hello " + mystring + " blablabla"        (i.e. a concatenation)
Run Code Online (Sandbox Code Playgroud)

我生气这么简单(连接)!非常感谢,我迷路了!

小智 18

C++方式:

std::wstring mywstring(mystring);
std::wstring concatted_stdstr = L"hello " + mywstring + L" blah";
LPCWSTR concatted = concatted_stdstr.c_str();
Run Code Online (Sandbox Code Playgroud)

  • 一个修改是`concatted`必须是`LPCWSTR`. (4认同)

Jac*_*nev 5

您可以使用StringCchCatW函数

  • @Alex`LPWSTR`不是现代C++,因此我们已经在该域之外.因此,如果在问题的域中存在实用的解决方案,为什么会将解决方案限制为现代C++?正如我上面所说,他最终需要将他的结果转换回"LPWSTR". (4认同)
  • 那不是 C++,或者当然不应该是。 (2认同)
  • @AlexChamberlain 问题是关于 _Visual C++_ 的。 (2认同)
  • @JacobSeleznev完全无关紧要; 它不是*现代*C++. (2认同)
  • @JBentley因为它成为一个安全和清晰的问题. (2认同)