0
我的平台是Windows 7 x64。此代码:VS变量周围的报告堆栈已损坏
#include <iostream>
#include <string>
#include <stdint.h>
#include <sstream>
using namespace std;
int main()
{
string line;
int c = 3;
while(c-- && getline(cin, line))
{
stringstream sstr;
sstr << line;
uint32_t data;
int r = sscanf(sstr.str().c_str(), "%d", &data);
if (r == 1)
{
cout << data << endl;
}
}
return 0;
}
以整数作为输入,打印它们并存在正常。如果我改变的data
类型uint16_t
,那么就从main()函数返回前,相较于2010年抛出一个错误:
运行时检查失败#2 - 堆栈周围的变量“数据”被损坏
我想知道为什么VS 2010在uint16_t
很生气?任何解释?
那么,你的平台上'int'的大小是多少? – 2013-03-06 18:47:06
作为奥利说,我的猜测将是整数大小 – 2013-03-06 18:47:54
它是4字节@OliCharlesworth – Donotalo 2013-03-06 18:48:17