I tried declaring a matrix and when I compile I get this:
extended initializer lists only available with -std=c++0x or -std=gnu++0x
And when trying another solution I get this:
ISO C++ forbids variable length array 'A' (line 16)
Here is the code of my last try:
#include<iostream>
#include<cmath>
#include<fstream>
#include<cstdlib>
using namespace std;
int main()
{
int m, l;
ifstream MatrixA ("A.txt");
MatrixA >> m;
MatrixA >> l;
int A [m][l];
for (int lineA = 0; lineA <= m; lineA++)
{
for (int colA = 0; colA <= l; colA++)
{
A [lineA][colA];
}
}
cout << "Matrix A: " << A[m][l] << endl;
return 0;
}
C++ does not support built-in arrays of variable size. If you need variably sized array dimensions you'll need to use something which does the necessary memory allocations dynamically. A relatively straight forward alternative is to use a std::vector
of std::vector
s:
std::vector<std::vector<int> > A(m, std::vector<int>(l));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.