I want to read this file with an application that is not linked to wxWidgets and thus I have to do this without the use of wxDataInputStream::ReadString. In the end I want the file content in an std::stringstream
The code for creating the file goes like
Code: Select all
...
wxDataOutputStream ofs(zip);
zip.PutNextEntry(zipEntryName);
ofs.WriteString(ss.str());
...
This works fine and i can unzip the file and the content is what I expect.
To read the file after unzipping i do something like
Code: Select all
...
wxFFileInputStream inStream(inFile);
wxDataInputStream inDStream(inStream);
std::stringstream ss;
ss << inDStream.ReadString().ToStdString();
...
How would I do the last step without any wxWidgets related classes?
I have tried the following where fileName is the name of the unzipped file produced by WxDataOutputStream::WriteString
Code: Select all
std::stringstream ss;
std::ifstream c_file(fileName, std::ios_base::in, std::ios_base::binary);
//Read the first 32 bits that is the length of the string written by WxDataOutputStream::WriteString
uint32_t string_size{0};
c_file.read(reinterpret_cast<char *>(&string_size), sizeof(string_size));
//try to read the rest of the file.
const std::string s(std::istreambuf_iterator<char>(c_file), {});
//s contains rubbish and is to short to have been filled with the entire file contents.
/Klas