#include <iostream>
#include <fstream> ///<文件I/O
using namespace std;
int main()
{
char sAuthor[20];
int nAge;
double nPay;
ofstream ioOutFile; ///<定义IO输出对象
ioOutFile.open("authorInfo.txt");
cout<<"Enter Your Name:";
cin.getline(sAuthor,20);
cout<<"Enter Your Age:";
cin>>nAge;
cout<<"Enter Your Month Pay:";
cin>>nPay;
ioOutFile<<fixed;
ioOutFile.precision(2);
ioOutFile.setf(ios_base::showpoint);
///<以上三句用来设置输出精度为小数点后两位
ioOutFile<<"Author Name is "<<sAuthor<<endl;
ioOutFile<<"Author Age is "<<nAge<<endl;
ioOutFile<<"Author`s Month Pay is "<<nPay<<endl;
ioOutFile.close();
system("pause");
return 0;
}
/**注意,使用完一个文件文件后,应该将其关闭
open和close应该成对使用
如果在程序运行之前文件不存在,方法open()将创建一个新的文件。但是,如果再次运行该程序,
默认情况下,open()将首先截断该文件,即将其长度截短到零——丢弃原有的内容,
然后将新的输出加入到该文件中。
警告:打开已有文件,默认长度截短为零——丢其原有的内容。
**/