赞
踩
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ofstream ok;
ok.open("test1.txt",ios::out);
ok<<"成功";
ok.close();
return 0;
}
拷贝zhy.txt文件到新的文件,应该如何写?
#include<iostream>
#include<fstream>
using namespace std;
void copyfile(const char* src,const char* des)
{
//src:源文件名称 des:目标文件名称 bits_to_copy:想复制的字节数
fstream infile;
fstream outfile;
char buf;
infile.open(src,ios::in|ios::binary);
if(!infile){cout<<"error";exit(-1);}
outfile.open(des,ios::trunc|ios::binary|ios::out);
if(!outfile){cout<<"error";exit(-1); }
while(infile.read( &buf,sizeof(buf)) )
{
outfile.write( &buf,sizeof(buf));
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。