I have a binary file to read from and inside the file are non-fixed lengths of data but they do have start and stop sequences.
Start Sequence is 0x1B 0x5B 0x30 0x48
Stop Sequence is 0x1b 0x5B 0x31 0x48
This particular file does have 28 entries in it, thought how many entries could be different.
I've read the binary file into a vector to the size of the file
ifstream datafile("myfile.bin", ios_base::in|ios_base::binary);
vector<char> buff;
int size = datafile.tellg();
buff.resize(size);
datafile.read(buff.data(), size);
Now I've tried to iterate over the vector byte by byte (as that is how it is stored in the vector right? but that's not quite what I want.
It would be nice to read over the vector writing the data to another (temp) variable and then stop writing to it when I see the Stop Sequence. Then continue on with the rest of the vector, writing to another variable until the next Stop Sequence is seen etc. Like writing to a vector<vector<char>> ?
Below is the iteration I do for byte-by-byte.
for (vector<char>::iterator it = buff.begin(); it != buff.end(); ++it)
{
if (*it == 0x1B)
{
// found ESC char
}
}
How might I set up reading from the binary file, writing the bytes up until the Stop Sequence and then repeating for the rest of the file?