码迷,mamicode.com
首页 > 编程语言 > 详细

c++实现两个文件的拼接。

时间:2015-06-07 10:58:33      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

  问题描述:

  要求把第二个文件拼接到第一个文件的末尾。 如把file2 拼接到 file末尾。 (直接复制一下不久行了嘛! 但是老师非让编程, 真是蛋疼!!)。例如:

file1: I am not responsible of this code. They made me write it, against my will.   file2: When I wrote this, only God and I understood what I was doing. Now, God only kowns.   拼接后: file1: I am not responsible of this code. They made me write it, against my will. When I wrote this, only God and I understood what I was doing. Now, God only kowns.  

知识点: 文件流类。

 

#include<iostream>
#include<fstream>
using namespace std;

const int maxn = 1000+10;

int main()
{
    char str[maxn]; 
    ifstream cin("file2.txt");
    ofstream cout("file1.txt", ios::app);
    while(cin.getline(str, maxn))
    {
        cout<<str<<endl;
    }
    return 0;
}

一周内请勿抄袭! 以防作业雷同!

c++实现两个文件的拼接。

标签:

原文地址:http://www.cnblogs.com/acm1314/p/4557759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!