您的位置:首页 > 编程语言 > C语言/C++

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

2015-06-10 09:20 295 查看
/*
*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;
}


知识点运用:简单地对文本进行操作
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: