【发布时间】:2020-11-03 23:56:53
【问题描述】:
直接用1212121221121212 + 34343434343434 = 1246464655464646 在cin 中输入值没有解决办法。为什么?
#include <iostream>
using namespace std;
int main() {
long int a, b, c;
char op, eq;
cout << "Input the formula: ";
cin >> a >> op >> b >>eq >> c;
long int sum;
if (op == '+') {
sum = a + b;
}
else {
sum = a - b;
}
if (sum == c) {
cout << "Correct";
}
else {
cout << "No Solution";
}
return 0;
}
【问题讨论】:
-
34343434343434 是一个 BFN,也就是一个大数。它可能不适合
int。检查所有 IO 事务后的流状态,以确保您阅读了您想阅读的内容。 -
或者,只使用更大的整数类型,例如
long long int或int64_t