Search code examples
c++operatorsvoid

Unknown compiler error in cout<< theoreticlly it works


#include <iostream>
using namespace std;

void matrice(int n){


cout<<"Input the number of the elements "<<endl;
cin>>n;
int D[n][n];
cout<<"Input the elements :";
for(int i=0;i<n;i++){
  for(int j=0;j<n;j++){
        cin>>D[i][j];

  }
}
int min;
for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
            if( min=0>D[i-1][j-1]){
        D[i-1][j-1]=min;
    }
    }
}
cout<<" The smallest element is : "<< min<<"and it is the"<< i <<" element ."  ;
}


int main(){
int i, min ,j,n;

int n1;
    cout<<"Decide: "<<endl;
    cout<<"Matrice[1]"<<"\t"<<"Vekcor[2]"<<endl;
cin>>n1;
if(n1==1){
    matrice(n);
}
else if(n1==2){
}
}



The problem is at line 22 at the cout and it gives this message: C:\Users\use\Documents\Dev C++\void_vektor.cpp|22|error: no match for 'operator<<' (operand types are 'std::basic_ostream' and '')|


Solution

  • The main issue is that you declare min inside the for loop, it will go out of scope as the loop exits.

    The bizarre error message is likely because of the std::min function. This is a good case study on why not to use using namespace std;.

    At first glance there are other issues in your code:

    In the future you should use compiler warnings.