这是我使用的代码。我通常会得到一个错误,称为“运行时检查失败#2 - 变量'字符串'周围的堆栈已损坏。”我不知道如何不破坏数据。有什么我可以做的吗?关于atol动作的C++错误
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
int result;
char string[5];
cout << "Enter a number in 5 digits (type 0's if less than 5 digits): ";
cin >> string;
result = atol(string);
cout << result << "\n";
system("pause");
return 0;
}
你输入了什么? –
理想情况下,使用C++时 - 避免使用原始字符数组 - std :: string为您提供所有您需要的内容......没有内存风险。 – parade