c++的问题 请问大家这个哪里错了
来源:百度知道 编辑:UC知道 时间:2024/09/21 06:42:10
#include<iostream.h>
void main()
{
int a,b;
cin>>a>>','>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<a<<" "<<b<<endl;
}
编译时候就出错,错误提示是:no operator defined which takes a right hand operand of type const char (or there is no acceptable conversion ) 看不明白啥意思
void main()
{
int a,b;
cin>>a>>','>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<a<<" "<<b<<endl;
}
编译时候就出错,错误提示是:no operator defined which takes a right hand operand of type const char (or there is no acceptable conversion ) 看不明白啥意思
估计你是先学的C语言吧。。。
cin不能那么用,cin>>a>>b;这样就可以,输入时以空格或者回车隔开就行
还有就是,你少空间声明;另外,头文件去掉.h,VC6.0可能需要
正确如下:
#include<iostream>
using namespace std;
void main()
{
int a,b;
cin>>a>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<a<<" "<<b<<endl;
}
cin>>a>>','>>b; //不能这样用
应该这样:
cin>>a>>b; //输入的时候,用空格作为分隔符
或者:
cin>>a;
if(cin.get() == ',')cin>>b;
cin>>a>>','>>b;
最好写成:
cin>>a;
cin>>b;
cin>>a>>','>>b;
这里有问题,cin不可以这样用的,可以改为:cin>>a;cin>>b;
你改了再试试看
cin语句中不能加常量
cin>>a>>','>>b; //不能这样用