我正在尝试编写简单的C++代码来读写文件。
问题在于我的输出文件比原始文件要小,而我卡在了找出原因上。
我的图片大小为6.6KB,但我的输出图片大约只有6.4KB。
#include <iostream>
#include <fstream>
using namespace std;
ofstream myOutpue;
ifstream mySource;
int main()
{
mySource.open("im1.jpg", ios_base::binary);
myOutpue.open("im2.jpg", ios_base::out);
char buffer;
if (mySource.is_open())
{
while (!mySource.eof())
{
mySource >> buffer;
myOutpue << buffer;
}
}
mySource.close();
myOutpue.close();
return 1;
}