每次使用数组和矩阵c++时都会出错

Error every time I use arrays and matrices c++

本文关键字:c++ 出错 数组      更新时间:2023-10-16

我正在为矩阵编写一个程序,我得到了错误:

错误C2109:下标需要数组或指针类型

错误C2064:术语的计算结果不是采用1个参数的函数

错误C2109:下标需要数组或指针类型

#include <iostream>
using namespace std;
int main()
{
char str[3][3] = { };
cout <<"Input first row secon row third row"<<endl;
cin >>str[0][0]>>str[0][1]>>str[0][2];
cout <<""<<endl;
cin >>str[1][0]>>str[1][1]>>str[1][2];
cout <<""<<endl;
cin >>str[2][0]>>str[2][1]>>str[2][2];
cout <<""<<endl;
str[3][0]= (str[0][0])[(str[1][1]*str[2][2])-(str[1][2]*str[2][1])];
str[3][1]= (-1)(str[1][0])[(str[0][1]*str[2][2])-(str[0][2]*str[2][1])];
str[3][2]= (str[2][0])[(str[0][1]*str[1][2])-(str[0][2]*str[1][1])];
str[3][3]= (str[3][0])+(str[3][1])+(str[3][2]);
cout <<str[3][3];
std::cin.get();
cin.get();
return 0;
}

您使用的是非法索引。您正在使用的数组是str[3][0]超出了绑定范围。最大数组总是比指定的长度少一个。您可以使用str[2][0]。