jeudi 14 février 2019

how to put a 2d string array in if statement?

i have problem comparing a string 2d array with 'X' in if statement

I'm trying to compare every cell in my array with 'X' but i get "no match for 'operator == ' error in line 14, so i guess i have problem putting the array inside this if statement

    #include <iostream>

    using namespace std;

    int main()
    {
        int n;
        cin >> n;
        string M[n][n];
        int k=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
               cin>>M[i][j];
               if(M[i][j]=='X')
                   k++;
           }
       }

         cout<<k<<endl;

         return 0;
   }

the error in line 14 "the if line" and it says "no match for 'operator == ' error

Aucun commentaire:

Enregistrer un commentaire