c++ - 将两个字符串相加以创建一个新的 LPSTR

标签 c++ winapi

此代码不可编译:

LPSTR a1 = "a1";
LPSTR lpResult = a1 + "a2";

如何获得指向“a1a2”字符串的长指针lpResult

最佳答案

一种选择是使用 std::string 连接。您还可以使用 Microsoft 的 StringCchCat功能。

这是一个例子:

#include <Strsafe.h>

//... later in your code:

LPSTR a1 = "a1";
LPSTR a2 = "a2";

TCHAR dest[ 5 ];
StringCchCopy(dest, 5, a1);  // copy "a1" into the buffer
StringCchCat(dest, 5, a2);   // concatenate "a2" into the buffer

关于c++ - 将两个字符串相加以创建一个新的 LPSTR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10401585/

相关文章:

c++ - 您将如何对函数的性能进行基准测试?

c# - 无法并行读取同一个文件

c++ - 如何在 C++ 中使 recv() 函数超时?

python - 如何使用python使用wifi?

delphi - 创建透明位图并UpdateLayeredWindow

c++ - 如何解锁 boost::upgrade_to_unique_lock(由 boost::shared_mutex 制成)?

c++ - 错误 : invalid cast from string to double. 如何从字符串转换为 double ?

c++ - WM_PAINT 基于按钮点击

c# - 创建并重命名新文件夹后,FolderBrowserDialog 显示不正确的 SelectedPath

c# - 是否可以通过 C#.NET 编写 Win32 .dll 文件?