There is a file filename.bin . It contains the following data:

 file1.txt'\0' Дальше контент..... file2.txt'\0' Дальше контент..... 

I need to "pull out" the file names. Format:

  • file name ends with '\ 0'

  • file size 4 byte number in LITTLE_ENDIAN

  • Those. filename.bin represents such a simple container view. It is very interesting if there can be any kind of content, i.e. contain the header of the above format? - gecube
  • And something about this "content" can you say? And it's better to just put the output hd filename.bin - avp
  • and what's the difference, what's the content? - KoVadim
  • No difference. Just to test it was possible on real data. - avp
  • a couple of minutes and I filed a file myself. The description is quite decent. - KoVadim

1 answer 1

Here is the idea

 #include <iostream> #include <fstream> int main() { std::ifstream file("filename.bin", std::ios::in | std::ifstream::binary); std::string fn; int n; while (std::getline(file, fn, '\0')) { file.read((char*)&n, sizeof(n)); file.seekg(n, file.cur); std::cout << "filename: " << fn << " content size: " << n << std::endl; } return 0; } 

There are a lot of features in the code - for example, it is assumed that sizeof (int) is 4 bytes, and the file is correct, and that the system where it is executed operates on numbers in little-endian.

  • It seems to work. Thank you so much! - jaroslav