第十四周 阅读项目 C++对文本输入输出

来源:互联网 发布:和讯期货软件 编辑:程序博客网 时间:2024/06/03 20:14
/**Copyright (c)2014,烟台大学计算机与控制工程学院*All rights reserved.*文件名称:d.cpp*作    者:张旺华*完成日期:2015年6月3日*版 本 号:v1.0*/#include<iostream>#include <fstream>#include<cstdlib>using namespace std;int main( ){    int a[10];    ofstream outfile("f1.dat",ios::out);//定义文件流对象,打开磁盘文件"f1.dat"    if(!outfile)                        //如果打开失败,outfile返回0值    {        cerr<<"open error!"<<endl;        exit(1);    }    cout<<"enter 10 integer numbers:"<<endl;    for(int i=0; i<10; i++) //向磁盘文件"f1.dat"输出数据    {        cin>>a[i];        outfile<<a[i]<<" ";    }    cout<<"The numbers have been writen to file. "<<endl;    outfile.close();       //关闭磁盘文件"f1.dat"    return 0;}

知识点运用:简单地对文本进行操作
0 0