变量周围的调试错误堆栈已损坏
Debug Error Stack Around Variable Was Corrupted
我是一名编程爱好者,遇到过一个错误,上面写着"运行时检查失败#2-变量"存储"周围的堆栈已损坏。"。
我的代码完全符合我的要求,但我不明白为什么会出现这个错误,如果有人能向我解释,我将不胜感激。谢谢!
#include <iostream>
using namespace std;
int main()
{
int store[4] = {};
for (int i = 0; i != 5; i++)
{
cout << "Enter the sales of store " << (i + 1) << ": ";
cin >> store[i];
}
cout << "nSALES BAR GRAPHn(Each * represents $100)n";
for (int i = 0; i != 5; i++)
{
int a = (store[i] / 100);
cout << "nStore " << (i + 1) << ": ";
for (int i = 0; i < a; i++)
{
cout << "*";
}
}
cout << "n";
system("pause");
}
您的for
循环不正确:
for (int i = 0; i != 5; i++)
这引用了store[4]
,如果您声明了int store [4]
,则它是越界的。如果你想将商店大小保持为4,你应该将循环更改为:
for (int i = 0; i < 4; i++)
相关文章:
- gdb错误:Backtrace已停止:上一帧与此帧相同(堆栈已损坏?)
- 变量周围的堆栈'...'已损坏
- 运行时检查失败 #2 变量"A"周围的堆栈已损坏
- 运行时检查失败 #2 - 变量"e"周围的堆栈已损坏。发生
- 运行时检查失败 #2 - 变量周围的堆栈'...'已损坏
- 运行时检查失败 #2 - 变量"l1"周围的堆栈已损坏
- 数组变量周围的堆栈已损坏
- 运行时检查失败 - 变量周围的堆栈已损坏
- 调试:运行时检查失败 #2 - 变量"LoggerThread"周围的堆栈已损坏
- 运行时检查失败 #2 - 变量"数字选择"周围的堆栈已损坏
- 运行时间检查:变量周围的堆栈已损坏
- 变量"name"周围的堆栈已损坏C++
- MS 工作室 17 变量周围的堆栈已损坏
- 错误:运行时检查失败 #2 - 变量周围的堆栈已损坏
- C++指针:数组的堆栈已损坏
- 变量周围的堆栈已损坏
- C++ 变量周围的堆栈已损坏
- 运行时检查失败 #2 - 变量周围的堆栈---已损坏
- VS2010和OpenCV:变量周围的堆栈已损坏
- 指针函数参数已损坏,堆栈已损坏