【发布时间】:2015-03-14 21:41:04
【问题描述】:
我得到一个错误的阅读:
Homework6_10_7.exe 中 0x5AAF40D9 (msvcr120d.dll) 处未处理的异常:>0xC0000005:访问冲突写入位置 0x006A0000。
运行此代码时:
int main()
{
//variables
const int SIZE = 30;
char first[SIZE];
char middle[SIZE];
char last[SIZE];
char full[100];
const char comma[2] = { ',', '\0'};
const char space[2] = { ' ', '\0' };
int length = 0;
//Get the user names
cout << "Enter your first name: ";
cin.getline(first, 30);
cout << "Enter your middle name: ";
cin.getline(middle, 30);
cout << "Enter your last name: ";
cin.getline(last, 30);
//Puts the given name values into the full desired format,
strcat(full, last);
strcat(full, comma);
strcat(full, space);
strcat(full, first);
strcat(full, space);
strcat(full, middle);
//outputs the full name array.
cout << "Welcome new user " << full << endl;
system("PAUSE");
return 0;
}
我有什么遗漏的吗? strcat 似乎是造成问题的原因,但我不知道为什么。 任何帮助表示赞赏,谢谢。
【问题讨论】:
-
strcat(full, last);你知道full最好已经包含一个有效的终止字符串,对吧?您的目前不确定。 -
你有一个错误。你没有使用
std::string。
标签: c++ visual-studio-2013 strcat