数组问题:变量周围的堆栈'arr'已损坏
Array issues: Stack around the variable 'arr' was corrupted
我正在编写一个请求数组的函数的中间,如果找到大写字母,则应该将整个行交换为Captial字母。否则,它只是打印功能。运行主函数直到可以检查Captial Letters的函数的部分是可以的,我会在标题中提到的错误。
主要功能:
#include <iostream>
#include "FuncA.h"
#include "printarr.h"
using namespace std;
void main()
{
char choice;
do
{
cout << "Welcome, choose a function to continue: " << endl << "n A for Uppercasing arrays. n B for Column sum. n C for String copying. n D for exit" << endl;
cin >> choice;
switch (choice)
case 'A':
funca();
}
while (choice != 'D');
}
和所讨论的功能:
#include <iostream>
#include "FuncA.h"
#include "printarr.h"
using namespace std;
void funca()
{
int rows = 0, cols = 0; //init
cout << "how many rows? ";
cin >> rows;
cout << "n how many cols? ";
cin >> cols;
char arr[][COLS] = {0};
for (int i = 0; i < cols; i++) // input
{
for (int j = 0; j < rows; j++)
{
cin >> arr[i][j];
}
}
for (int i2 = 0; i2 < cols; i2++) // capcheck and printing if caps not detected
{
for (int j2 = 0; j2 < rows; j2++)
{
if (arr[i2][j2] >= 90 || arr[i2][j2] <= 65)
{
printarr(arr, rows, cols);
}
}
}
}
如何解决此问题?我尝试更改COLS的大小(在.H文件中定义了大小(,但这无效。
您对arr
的声明等于char arr[1][COLS]
。第一个"维度"的任何非零索引都将超出范围。
如果您想要一个在运行时设置的"数组",则使用std::vector
:
std::vector<std::vector<char>> arr(cols, std::vector<char>(rows));
相关文章:
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 为什么C中的通用链表中存储的数据已损坏
- gdb错误:Backtrace已停止:上一帧与此帧相同(堆栈已损坏?)
- 变量周围的堆栈'...'已损坏
- 运行时检查失败 #2 变量"A"周围的堆栈已损坏
- 两个垫子的 OpenCV 数据是相同的,但使用 Mat::at 检索时的值已损坏
- 运行时检查失败 #2 - 变量"e"周围的堆栈已损坏。发生
- 变量周围的堆栈'sortArray'已损坏
- 变量周围的堆栈'folderPath'已损坏
- 在为 iOS 构建 aws-sdk-cpp 时,cmake 上的 CXX 编译器错误已损坏
- 运行时检查失败 #2 - 变量周围的堆栈'...'已损坏
- AES-128 CFB-8解密的前16个字节已损坏
- 运行时检查失败 #2 - 变量"l1"周围的堆栈已损坏
- C++:此代码可以编译,但引发运行时检查失败 #2 - 围绕变量周围的堆栈'num'已损坏。发生
- 图像在本地主机上显示已损坏
- 检查工作正常的 CXX 编译器:/cygdrive/c/cygwin64/bin/clang++ -- 已损坏
- 数组变量周围的堆栈已损坏
- 运行时检查失败 - 变量周围的堆栈已损坏
- 串行端口的传入值有时已损坏或丢失
- 数组问题:变量周围的堆栈'arr'已损坏