LPWSTR字符串的连接
Concatenation of LPWSTR strings
在Visual C++中,我有一个
LPWSTR mystring;
这已经在代码中的其他地方定义了。
我想创建一个新的LPWSTR,其中包含:
"hello " + mystring + " blablabla" (i.e. a concatenation)
这么简单的事情(串联(让我很生气!提前谢谢你,我迷路了!
C++方式:
std::wstring mywstring(mystring);
std::wstring concatted_stdstr = L"hello " + mywstring + L" blah";
LPCWSTR concatted = concatted_stdstr.c_str();
您可以使用StringCchCatW函数
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"是"out_w"的LPWSTR包装。因此,只要"out_w"在作用域中,就可以使用它。此外,您不需要删除"out",因为它绑定到"out_w"生命周期。
这与"user529758"给出的答案大致相同,但"chris"提出了修改意见。
相关文章:
- 在 c++ 中连接字符串和整数,以便在 C++ 11 不支持计算机的情况下读取多个文件
- 这两个C++语句连接字符串有什么区别?
- 连接字符串族
- 如何使用 + 运算符连接字符串
- 如何按照 Google C++风格指南连接字符串文字?
- 我的字符串类的 += 运算符有问题,它没有正确连接字符串
- 如何编写模板函数来添加整数但连接字符串和字符类型?
- 无法创建栅格堆栈,因为我无法连接字符串(dir_name + 文件名)
- 如何在不使用对象的情况下连接字符串、整数和浮点数
- 在std :: string中连接字符串的选项
- 连接字符串的最佳方法是什么?
- 在实体框架C /CLI上配置连接字符串
- 在 c++ 中连接字符串和 int
- 如何连接字符串并传递给 system() 调用
- 有没有办法方便地为 Winsock send() 生成 HTTP 标头,而不是手动连接字符串
- 在可变参数模板函数中连接字符串(和数字)
- 连接字符串时出现意外问题
- 如何在 c++ 中连接字符串
- 自动连接字符串和 int C++
- 我的c++程序在我不告诉他的地方连接字符串