Search code examples
c++codeblocksclion

Why does code work in codeblocks 16.01 but doesn't i the newest version of Clion


#include<iostream>
#include<iomanip>

using namespace std;

int main(){
int r,k;

    cout << "Unesite broj redova:";
    cin >> r;
    cout << endl << "Unesite broj kolona:";
    cin >> k;

int A[r][k];

for(int i = 0; i < r; i++){
    for (int j = 0; j < k; j++){
        cout << "A[" << i << "][" << j <<"] = ";
             A[i][j];
    }
cout<< endl;
}

} I'm new to clion after using codeblock for 6 months. I got a clion liscenes, I opened my code which i started writing in codeblocks and i doesn't want to work in clion. All help is appreciated


Solution

  • This construct

    int A[r][k];
    

    is called variable length array (VLA) and is not part of C++. Some compilers provides it as an extension, others don't.

    You should use either new or std::vector or any other constructs, instead of VLAs.

    For example, with vectors, A becomes:

    std::vector<std::vector<int>> A(r, vector<int>(k, 0));
    

    and the rest stays the same.