读书人

队列与文件合并的概念.能给个帮助吗?该

发布时间: 2012-02-08 19:52:21 作者: rapoo

队列与文件合并的概念.能给个帮助吗?
现在上课在讲c语言的 队列 与 文件合并 的概念,我不是很懂,有谁精通这个方面的话.就给我一点帮助吧.有例题吗?给我解释一下好吗?
队列 与 文件合并:

[解决办法]
//文件合并,就是把两个文件中的内容合并到第三个文件中,下面这个程序可以看一下
#include <iostream>
#include <fstream>
using namespace std ;

classCFile
{
private:
fstreaminf , ouf ;
charfile1[ 20 ] , file2[ 20 ] ;
public:
CFile() ;
~CFile() ;
voidCFile_cat() ;
voidCFile_write() ;
} ;
CFile::CFile()
{
cout < < "Frist: " ;
cin > > file1 ;
cout < < "Second: " ;
cin > > file2 ;
inf.open( file1 , ios::in , 0 ) ;
if( !inf )
{
cout < < "Can 't open file! " ;
return ;
}
ouf.open( file2 , ios::in|ios::out , 0 ) ;
if( !ouf )
{
cout < < "Can 't creata file! " ;
return ;
}

return;
}
CFile::~CFile()
{
inf.close() ;
ouf.clear() ;
}
voidCFile::CFile_cat()
{
charch ;
ouf.seekp( 0 , ios::end ) ;
inf.get( ch ) ;
while( !inf.eof() )
{
ouf.put( ch ) ;
inf.get( ch ) ;
}
return;
}
voidCFile::CFile_write()
{
charch ;
ouf.seekp( 0 ) ;
ouf.get( ch ) ;
while( !ouf.eof() )
{
cout < < ch ;
ouf.get( ch ) ;
}
return;
}
intmain()
{
CFileD ;
D.CFile_cat() ;
D.CFile_write() ;
return0 ;
}

读书人网 >C++

热点推荐