【问题标题】:VS reporting stack around the variable was corruptedVS 报告变量周围的堆栈已损坏
【发布时间】:2013-03-06 18:45:20
【问题描述】:

我的平台是 Windows 7 x64。这段代码:

#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()函数返回之前,VS 2010会抛出一个错误:

运行时检查失败 #2 - 变量“数据”周围的堆栈已损坏

我想知道为什么 VS 2010 对uint16_t 如此生气?有什么解释吗?

【问题讨论】:

  • 那么,您平台上int 的大小是多少?
  • 正如 Oli 所说,我的猜测是整数大小
  • 它是 4 字节 @OliCharlesworth
  • @Donotalo:好的,那这回答你的问题了吗?
  • 我不知道hd。不管怎么说,还是要谢谢你。 :)

标签: c++ visual-studio-2010 runtime-error


【解决方案1】:

可能是因为 %d 指的是 32 位值。尝试 %hd 获取 16 位值。

【讨论】:

    猜你喜欢
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2012-11-08
    • 2019-09-04
    • 2020-07-26
    • 1970-01-01
    相关资源
    最近更新 更多