65,187
社区成员




简单问题复杂化,楼主小心.
#include <iostream>
#ifndef FILEBINARYOPERATORS_H_INCLUDED
#include <iostream>#include <iostream> // 数据流输入/输出
#include <fstream>
#include <string> // 字符串类
using namespace std;
int Calculate(char& algo, int& x , int& y); // 计算 +-*/
int main()
{
char algo;
int x , y;
ifstream fin("data.txt");
while (fin) {
fin >> algo >> x >> y;
fin.get(); // 加入这行,避免最后一行输出两次
cout << x << algo << y << "=" << Calculate(algo, x , y) << endl;
}
return 0;
}
int Calculate(char& algo, int& x , int& y)
{
int ret = -1;
switch (algo) {
case '+' : ret = x + y;
break;
case '-' : ret = x - y;
break;
case '*' : ret = x * y;
break;
case '/' : ret = x / y;
break;
}
return ret;
}
#include <iostream> // 数据流输入/输出
#include <string> // 字符串类
using namespace std;
int main()
{
char algo;
int x , y;
int ret;
cin >> algo >> x >> y;
switch (algo) {
case '+' : ret = x + y;
break;
case '-' : ret = x - y;
break;
case '*' : ret = x * y;
break;
case '/' : ret = x / y;
break;
}
cout << x << algo << y << "=" << ret << endl;
return 0;
}