| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1789 人关注过本帖
标题:关于 ofstream ios::app 的问题
只看楼主 加入收藏
sfjm888168
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-12-16
收藏
 问题点数:0 回复次数:0 
关于 ofstream ios::app 的问题
#include <iostream>
#include <fstream>
using namespace std;
void savefile()
{
    int a[10],b[10];
    ofstream outfile1("f1.dat"),outfile2("f2.dat");
    int j=1;
    for (int i=0;i<10;i++)
    {
        a[i]=j;
        outfile1<<a[i]<<" ";
        j++;
    }
    for (i=0;i<10;i++)
    {
        b[i]=j;
        outfile2<<b[i]<<" ";
        j++;
    }
    outfile1.close();
    outfile2.close();
}

void getfile()
{
    int a[10],b[10];
    ifstream infile1("f1.dat"),infile2("f2.dat");
    for (int i=0;i<10;i++)
    {
        infile1>>a[i];
        cout<<a[i]<<" ";
    }
    cout<<endl;
    for (i=0;i<10;i++)
    {
        infile2>>b[i];
        cout<<b[i]<<" ";
    }
    cout<<endl;
    infile1.close();
    infile2.close();
}

void addfile()
{
    ifstream infile("f1.dat");
    ofstream outfile("f2.dat",ios::app);
    int a[10];
    for (int i=0;i<10;i++)
    {
        infile>>a[i];
        outfile<<a[i]<<" ";
        cout<<a[i];
    }
    infile.close();
    outfile.close();
}
int main()
{
    savefile();
    addfile();
    getfile();
    return 0;
}

运行后,不能在 f2.dat 文件后面加入数据,请大家指教一下
搜索更多相关主题的帖子: ios app ofstream 
2007-12-16 16:22
快速回复:关于 ofstream ios::app 的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014837 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved