| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付赛孚耐:软件保护加密专家
身份认证令牌USB KEY   
共有 313 人关注过本帖
标题:关于 ofstream ios::app 的问题
收藏  订阅  推荐  打印 
sfjm888168
Rank: 1
等级:新手上路
帖子:1
积分:110
注册:2007-12-16
关于 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
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.059520 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved