1

error: no match for operator<< in std::operator<< <std::char_traits<char> >(*&std::cout),((const char*)


#include <iostream>
using namespace std;

int ContarDig (int num){
    int contar=1;
    while (num>9){
        num=num/10;
        contar=contar+1;
    }
    return contar;
}
void arreglo(int a[], int t){
    for(int i=(ContarDig(t)-1); i>=0; i--){
        a[i]=t%10;
        t=t/10;
        cout <<"valor posicion[" << i << "]= "<<a[i]<<endl;
    }
}
void invertir(int A[],int x){
    int l=(ContarDig(x)/2);
    int i=0;
    int f=ContarDig(x);
    for(l;l>=0;l--){
        int b=A[i];
        A[i]=A[f];
        A[f]=b;
        i++;
        f--;
    }
    for (i;i<=ContarDig(x);i++){
        cout <<"valor posicion[" << i << "]= "<<A[i]<<endl;
    }
}
int main(int argc, char *argv[]) {
    int x;
    cout<<"Digite un numero para invertir"<<endl;
    cin>>x;
    int A[ContarDig(x)];
    arreglo (A,x);
    cout<<"========================================================================"<<endl;
    cout<< "El arreglo invertido es:" << invertir(A,x) << endl;
    return 0;
}

So, I would like to know how to solve my problem, its objective is to have an array and invert it.

#include <iostream>
using namespace std;

int ContarDig (int num){
    int contar=1;
    while (num>9){
        num=num/10;
        contar=contar+1;
    }
    return contar;
}
void arreglo(int a[], int t){
    for(int i=(ContarDig(t)-1); i>=0; i--){
        a[i]=t%10;
        t=t/10;
        cout <<"valor posicion[" << i << "]= "<<a[i]<<endl;
    }
}
void invertir(int A[],int x){
    int l=(ContarDig(x)/2);
    int i=0;
    int f=ContarDig(x)-1;
    for(l;l>=0;l--){
        int b=A[i];
        A[i]=A[f];
        A[f]=b;
        if (ContarDig(x)==2)
            break;
        i++;
        f--;
    }
}
int main(int argc, char *argv[]) {
    int x;
    cout<<"Digite un numero para invertir"<<endl;
    cin>>x;
    int A[ContarDig(x)];
    arreglo (A,x);
    cout<<"========================================================================"<<endl;
    cout<< "El arreglo invertido es:" <<endl;
    invertir(A,x);
    for (int i=(ContarDig(x)-1);i>=0;i--){
        cout <<"valor posicion[" << i << "]= "<<A[i]<<endl;
    }
    return 0;
}

This is the new version of my program and now it runs perfectly.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
user3553038
  • 13
  • 1
  • 4
  • 1
    invertir(A,x) returns void in your code. So why and what do you want to print on the console? – Mantosh Kumar Apr 20 '14 at 02:20
  • You`re right, I need to create a new function to print my new array, and erase the last part from Invertir(A,x) – user3553038 Apr 20 '14 at 02:29
  • Ok, write the new function which would erase the elements.Please share your implementation which you have tried so far and then we can help you out. – Mantosh Kumar Apr 20 '14 at 02:34

1 Answers1

1

The error related to the title stems from this line:

cout<< "El arreglo invertido es:" << invertir(A,x) << endl;

The function invertir () returns void, and can't be printed. To the compiler, that's like writing std:: cout <<;, which is invalid. Change the return type of the function to one appropriate, or, simply don't try to print it. Call the function and allow it to print normally (since there's calls to std:: cout:: operator << () in the function).

You should attempt to interpret these errors that you get. Although the errors you get for such simple mistakes span pages (I got 194 lines of errors), changing just one line of code fixes it all. Don't be intimidated, check the line number you are given, and look around that code for simple mistakes.

My error looked like this, and a whole bunch more.

test92.cpp: In function ‘int main(int, char**)’:
test92.cpp:41:39: error: no match for ‘operator<<’ 
  (operand types are ‘std::basic_ostream<char>’ and ‘void’)

That's all you need.

smiling_nameless
  • 1,047
  • 1
  • 9
  • 23
  • This may seem a little late to comment on a post, but +1 for the following good piece of advice: "Don't be intimidated, check the line number you are given, and look around that code for simple mistakes." – J. Allan Aug 30 '16 at 01:56