gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 03:37:33 25 4
gpt4 key购买 nike

此代码不可编译:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com