以下程序期望用户以混合分数格式“whole_numbernumerator/denominator”输入,并将值分配给各个变量。
#include<iostream>
using namespace std;
int main()
{
int whole, numerator, denominator;
cout << "Input format: i<space>n/d" << endl;
cin >> whole;
cin.ignore(1000, ' ');
cin >> numerator;
cin.ignore(1000, '/');
cin >> denominator;
cout << whole << endl;
cout << numerator << endl;
cout << denominator << endl;
return 0;
}
Input1:
123 345/678
Output1:
123
345
678
Input2 :
1111111111 1111111111/1111111111
Output2:
1111111111
1111111111
1111111111
Input3:
2222222222 2222222222/222222222 Output3
:
2147483647
0
0
I haven't been able to figure out why the program doesn't work for输入 3。