【发布时间】:2014-05-05 11:39:14
【问题描述】:
我正在尝试编写简单的 C++ 代码来读取和写入文件。 问题是我的输出文件比原始文件小,我一直在寻找原因。 我有一个 6.6 kb 的图像,我的输出图像大约是 6.4 kb
#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;
}
【问题讨论】:
-
我试图用它来获取它的二进制字符如:cout(buffer);
标签: c++ fstream ifstream ofstream