gpt4 book ai didi

c++ - Const char * 与 const wchar_t*(串联)

转载 作者:搜寻专家 更新时间:2023-10-31 01:57:29 24 4
gpt4 key购买 nike

哪种连接方式最好?

const char * s1= "\nInit() failed: ";
const char * s2 = "\n";
char buf[100];
strcpy(buf, s1);
strcat(buf, initError);
strcat(buf, s2);
wprintf(buf);

它给出了错误。正确的做法应该是什么?

谢谢。

最佳答案

我认为正确的做法是:

std::string msg = std::string("Init() Failed ") + initError + "\n";
std::cout<<msg;

std::cout<<"Init() Failed "<<initError<<"\n";

关于c++ - Const char * 与 const wchar_t*(串联),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5552806/

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