|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
从文件source.txt中读取内容,保存到destination.txt文件中,程序执行后,每次目标文件中只有最后一个字符,为什么?求大神解决
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream in("F:\\source.txt", ios::in);
if (!in)
{
cerr << "打开源文件失败" << endl; system("pause");
return 0;
}
ofstream out("F:\\destination.txt",ios::out|ios::app);
if (!out )
{
cerr << "打开目标文件失败" << endl; system("pause");
return 0;
}
static char buf[100];
while (in >> buf[100]);
{
out << buf[100];
}
cout << endl; system("pause");
in.close();
out.close();
return 0;
}
while (in >> buf[100]);
{
out << buf[100];
}
进也在100,出也在100,不一个还想几个。用个变量从 1 到 100 i++啊。
|
|