基本输入输出之将输出写入文件
#include<iostream>
#include<fstream>//使用用于文件输入和输出的fstream头文件。
usingnamespace std;
int main()
{
double income=123.45,expenses=987.65;
int week=7,year=2006;
ofstream outfile("A.txt");//写入文件。
outfile<<"Week="<<week<<endl;<<"Year="
<<year<<endl;
outfile<<"Income="<<income<<endl
<<"Expenses="<<expenses<<endl;
outfile.close();
return0;
}
/*打开文件作为输出的位置。
ostream outfile("A.txt");
关闭输出文件:outfile.close();

浙公网安备 33010602011771号