gpt4 book ai didi

c++ - 将 const char 转换为 char 时出现未处理的异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:06:05 25 4
gpt4 key购买 nike

在过去的 30 分钟里,我一直在尝试将 const char 转换为 char。这就是我得到的。

 string atr; 

getline(cin,atr); // Start off with a string because getline takes nothing else.
const char *buffA = atr.c_str(); // Create a const char of the string converted to a const char.
char *buff = ""; // Create a new char to hold the converted result.
strcat(buff,buffA); // Do the conversion.
parseargs(buff); // Pass the data on.

但是,我得到一个未处理的异常。我不知道为什么。我实际上只是在控制台中输入“try”作为我唯一的参数。

最佳答案

尝试使用 C++ 而不是 C 习语:

std::vector<char> data(atr.begin(), atr.end());
data.push_back('\0');
parseargs(&data[0]);

关于c++ - 将 const char 转换为 char 时出现未处理的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18054774/

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