使用C++做文件处理时常用的几个函数 查看更多见:李飞阳
文件的打开与关闭 (open和close函数)
文件读取之前,使用open函数进行打开。文件使用完毕后,使用close命令关闭。
infile.open("E:\\hello.txt");
infile.close();
文件读取与写入(infile >> income,outfile << "income:")
C++中可以调用库
#include<fstream>
之后可以使用,">>"和"<<"输入输出流的形式进行文件的读取
while (infile >> income)
{
if (income < cutoff)
tax = rate1*income;
else
tax = rate2*income;
outfile << "income:"<<left<<setw(6) << income << right<<setw(8) << "Tax:" <<tax<&l