error: no match for
operator<<
instd::operator<< <std::char_traits<char> >(*&std::cout),((const char*)
错误:在std中,操作符< <在std中:<< <:char_traits> >(*&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.
这是我的程序的新版本,现在运行得很好。
1 个解决方案
#1
1
The error related to the title stems from this line:
与标题相关的错误源于这一行:
cout<< "El arreglo invertido es:" << invertir(A,x) << endl;
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).
函数invertir()返回void,不能打印。对于编译器来说,这就像写入std:: cout <<;这是无效的。将函数的返回类型更改为一个适当的,或者,简单地不尝试打印它。调用该函数并允许它正常打印(因为有对std的调用:cout::操作符<<()在函数中)。
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.
你应该试着去解释你得到的这些错误。尽管您在这样简单的错误中所犯的错误跨越了页面(我有194行错误),但是只更改一行代码就可以解决所有问题。不要被吓倒,检查你所给出的行号,并查看代码中简单的错误。
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.
这是你所需要的。
#1
1
The error related to the title stems from this line:
与标题相关的错误源于这一行:
cout<< "El arreglo invertido es:" << invertir(A,x) << endl;
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).
函数invertir()返回void,不能打印。对于编译器来说,这就像写入std:: cout <<;这是无效的。将函数的返回类型更改为一个适当的,或者,简单地不尝试打印它。调用该函数并允许它正常打印(因为有对std的调用:cout::操作符<<()在函数中)。
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.
你应该试着去解释你得到的这些错误。尽管您在这样简单的错误中所犯的错误跨越了页面(我有194行错误),但是只更改一行代码就可以解决所有问题。不要被吓倒,检查你所给出的行号,并查看代码中简单的错误。
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.
这是你所需要的。