我正在尝试编写霍夫曼编码器,但出现了一些压缩错误。我将问题确定为 put() 到 ofstream 的字符与来自同一文件的 read() 字符之间的不匹配。
此问题的一个具体实例:
- put() 写入 ASCII 字符 10(换行)
- read() 读取 ASCII 字符 13(回车)
我想读取和放置读取和写入原始数据(没有字符翻译)我不确定为什么会这样。有人可以帮帮我吗?
这是写入压缩文件的 ofstream 实例:
std::ofstream compressedFileStream(getCompressedFileName(),std::ios::binary||std::ios::ate);
和读取相同的 ifstream 实例
std::ifstream fileInput(getFileName()+".huf",std::ios::binary);
代码在Windows 7上运行,程序中的所有流都以二进制模式打开。
最佳答案
由于打字错误,无法以二进制模式打开:
std::ofstream compressedFileStream(getCompressedFileName(),std::ios::binary||std::ios::ate)
应该是:
std::ofstream compressedFileStream(getCompressedFileName(),std::ios::binary|std::ios::ate)
// ^
|
,不是||
。
关于c++ - put 和 read 字符不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8776284/