基本输入输出之将输出写入文件

#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();
posted @ 2012-06-22 17:32  蚂蚁踩死了大象  阅读(182)  评论(0)    收藏  举报