#include <fstream>
using namespace std;
const int cutoff = 6000;
const float rate1 = 0.3;
const float rate2 = 0.6;
int main() {
ifstream infile;
ofstream outfile;
int income, tax;
infile.open("income.in");
outfile.open("tax.out");
while (infile >> income) {
if (income <= cutoff)
tax = rate1 * income;
else
tax = rate2 * income;
outfile << "Income = " << income << " greenbacks\n" << "Tax = " << tax << " greenbacks\n";
}
infile.close();
outfile.close();
return 0;
}
测试文件是否打开
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;
ofstream outFile
int i;
int j;
inFile.open("input.dat");
if (!inFile) {
cerr << "Unable to open input" << endl;
exit(0);
}
...
}
1949

被折叠的 条评论
为什么被折叠?



