#include<iostream>
#include<fstream>
#include<iterator>
#include<string>
#include<conio.h>using namespace std;void main()
{
char data;
int a_file_size=0,b_file_size=0; fstream a_file;
fstream b_file; a_file.open("input.txt");
b_file.open("output.txt"); if(!a_file||!b_file)
{
cerr<<"!!unable to open the necessary files.\n";
return;
} /*while(a_file.get(data))
a_file_size ++;
while(b_file.get(data))
b_file_size ++; cout<<a_file_size<<" "<<b_file_size<<endl;*/
while(a_file.get(data))
{
cout<<data;
b_file.put(data);
}
_getch();
}
注释中的语句一旦执行,文件就会不能拷贝,我想是不是前两个循环把文件指针移动到了文件尾部,所以while判断时就推出来了。请问用什么语句可以移动文件指针到头部?
#include<fstream>
#include<iterator>
#include<string>
#include<conio.h>using namespace std;void main()
{
char data;
int a_file_size=0,b_file_size=0; fstream a_file;
fstream b_file; a_file.open("input.txt");
b_file.open("output.txt"); if(!a_file||!b_file)
{
cerr<<"!!unable to open the necessary files.\n";
return;
} /*while(a_file.get(data))
a_file_size ++;
while(b_file.get(data))
b_file_size ++; cout<<a_file_size<<" "<<b_file_size<<endl;*/
while(a_file.get(data))
{
cout<<data;
b_file.put(data);
}
_getch();
}
注释中的语句一旦执行,文件就会不能拷贝,我想是不是前两个循环把文件指针移动到了文件尾部,所以while判断时就推出来了。请问用什么语句可以移动文件指针到头部?
解决方案 »
- 关于在父窗口中读取子窗口中打开的excel表的路径
- 请问前辈们"保存全部网页"怎么实现?
- 请教INI循环读写的问题
- 用VS2005编写C++基于对话框的程序,点击按钮添加单击事件时显示重载函数XXX已存在
- SQL 语句
- 提问一个编辑框指定为int型成员变量的问题。
- 简单的问题,怎么让一个模态对话框建立后自动执行一个函数?
- 如果在VC++中Cpp文件使用了彩色编码,用什么方法可以在保持代码格式和彩色编码的情况下,拷贝到WORD文档中
- 在没有VC环境的机器上运行时,Ado Data grid Grid控件就不能显示出来.(在线等待)
- !!急(关于CScrollview)
- 我最近 光盘 一放进光驱就死机 不知道是怎么回事
- 帮帮忙!!!
seekg(0, std::ios::beg);
but you should be able to do something likefstream a_file;
a_file.open("input.txt");
a_file.seekg(0, std::ios::end);
int length = a_file.tellg();
std::ofstream b_file("output.txt, std::ios_base::binary);std::copy(std::istreambuf_iterator<char>(a_file),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(b_file));or
b_file << a_file.rdbuf();
std::ifstream a_file("input.text", std::ios_base::binary);
std::ofstream b_file("output.txt", std::ios_base::binary);std::copy(std::istreambuf_iterator<char>(a_file),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(b_file));or
b_file << a_file.rdbuf();