It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




7年前关闭。




我有两个字符串,我想对其加以概括,因此,我使用了这段代码
char* a = "Hel"; char* b = "lo"; strcat(a,b);,但是当我运行我的应用程序时,它显示此错误Access violating writing location

最佳答案

它们都是(ab)字符串文字-您无法写入它们。实际上,您根本不应该使用char *a = "Hel";;您应该使用char const *a = "Hel";,在这种情况下,代码甚至都不会编译。

尝试这样的事情:

std::string a = "Hel";
std::string b = "lo";

std::string c = a + b;

C++中的strcat(即使正确使用)充其量也令人怀疑。

10-08 11:14