странная ошибка с boost :: iostreams :: gzip_decompressor в переполнении стека

все

Я разрабатываю, чтобы сжимать и распаковывать с Boost в C ++.

мои коды ниже:

#include <stdio.h>
#include <vector>
#include <string>

#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>

char *txtFile   = "D:/Temp/plainTest.txt";
char *txtFile2  = "D:/Temp/plainTest_.txt";
char *binFile   = "D:/Temp/plainTest.bin";

// compress
std::ifstream inStream(txtFile, std::ios_base::in);
std::ofstream outStream(binFile, std::ios_base::out);
boost::iostreams::filtering_streambuf< boost::iostreams::input> in;
in.push( boost::iostreams::gzip_compressor());
in.push( inStream );
boost::iostreams::copy(in, outStream);

// decompress
std::ifstream inStream2(binFile, std::ios_base::in);
std::ofstream outStream2(txtFile2, std::ios_base::out);
boost::iostreams::filtering_streambuf< boost::iostreams::input> in2;
in2.push( boost::iostreams::gzip_decompressor());
in2.push( inStream2 );
boost::iostreams::copy(in2, outStream2);   --->   this line gives me the following error

Файл plainText.txt содержит эти символы.

The following line is in error

std::ofstream ofs
The compiler would've spit out a warning (at least) if your file was called jest; but

Это дает мне ошибку.

First-chance exception at 0x75692EEC in C_test.exe: Microsoft C++ exception: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::iostreams::zlib_error> > at memory location 0x00D8E074.

If there is a handler for this exception, the program may be safely continued.

И память на 0x75692EEC как

0x75692EEC  8b 4c 24 54 33 cc e8 9d a2 ff ff 8b e5 5d c2 10 00 8b 45 10 83 f8 0f 77 18 89 44 24 10 c1 e0 02 50 51 8d 44 24 1c 50 e8 c9 ad ff ff 83 c4 0c eb c5 6a 0f 58 eb e3 90 90 90 90 90 8b ff 55  ?L$T3????..??]?..?E.??.w.?D$.??.PQ?D$.P???..??.??j.X????????.U

Но самое смешное, если я удалю OFS из plainText.txt как

The following line is in error

std::ofstream
The compiler would've spit out a warning (at least) if your file was called jest; but

Ошибка исчезнет, ​​и она выдаст plainText2.txt безупречной.

Что я сделал не так?

РЕДАКТИРОВАТЬ Я указал, линия дает мне ошибку.

0

Решение

Я думаю, что вам нужно указать, что выходной поток является двоичным:

std::ofstream outStream(binFile, std::ios_base::binary);

Затем, после записи, выполните outStream.close () (чтобы убедиться, что сжатый вывод сброшен; вместо этого вы можете вызвать flush (), но close () более вероятно будет работать на всех файловых системах). Затем откройте файл для чтения с binary также. Обратите внимание, что нет необходимости указывать std::ios_base::in (out), так как это значение по умолчанию для std :: ifstream (ofstream).

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector