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
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
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.
Source: https://ru.stackoverflow.com/questions/285066/
All Articles