c++输入问题,求高手解答

来源:百度知道 编辑:UC知道 时间:2024/09/21 15:30:50
在c++程序编好运行时要输入两个数字为程序中两个数a,b赋值,怎样才能输入这两个数字时用“,”隔开,而不是默认的空格。
(强调~~~~~是在c++程序编好运行时的输入!!!!)

简单处理一下就ok了。

#include <iostream>
using namespace std;
void main()
{

int a,b,c;
char ch; //中间加个字符
cin>>a>>ch>>b>>ch>>c;
cout<<a<<" "<<b<<" "<<c<<endl;
}

#include <iostream>
using namespace std;

void main()
{
int a,b,c;
cin>>a;
cin.get(); //或用这样也行
cin>>b;
cin.get();
cin>>c;
cin.get();
cout<<a<<" "<<b<<" "<<c<<endl;
}

这个问题比较无聊,下面是一个解决办法

int main()
{
int a,b;
char c;
cout <<"输入:";
cin>>a>>c>>b;
cout <<a<<endl<<b<<endl;
return 0;
}

或者可以试试
cin>>a;
cin.ignore(1);
cin>>b;

这样你就只能用,作为分