本人新手,在线跪求 大哥大姐帮帮忙。。。 急啊
如何实现:
在磁盘上建立一个文本文件,先写入内容,再将该文件读出显示在显示屏上,然后在将文件复制到另一个文件中,最后将两个文件连接成一个文件。。
、
急啊 。。。。 5555
[解决办法]
在回贴了敲的,你看看可以不,没写错误处理,自己加吧:)
// copyfile.cpp : Defines the entry point for the console application.
//
#include "iostream "
#include "fstream "
#include "string "
using namespace std;
int main()
{
// 建立一文件 data.txt
ofstream of( "data.txt ");
// 写如内容
of < < "good good study " < <endl;
of < < "day day up " < <endl;
of.close();
// 显示文件内容
ifstream ef( "data.txt ");
char str[128];
while (!ef.fail())
{
ef.getline(str, sizeof(str) - 1);
cout < <str < <endl;
}
ef.close();
// 复制到另外一个文件 copy.txt
ef.open( "data.txt ");
of.open( "copy.txt ");
of < <ef.rdbuf();
of.close();
ef.close();
// 合成一个 comb
ofstream cf( "comb.txt ");
ef.open( "data.txt ");
cf < <ef.rdbuf();
ef.close();
ef.open( "copy.txt ");
cf < <ef.rdbuf();
ef.close();
cf.close();
return 0;
}