Something along these lines would do the job. It's clumsy, but hopefully easy to understand. I don't promise it's exactly correct, but this sort of thing would do it. It ends up with lineStore, a vector of lines structures, each one of which is the three values. I've assumed that it's a text file that literally reads as above.
This method does not rely on every short line starting with 1 (but does rely on every short line beginning with a single digit or character). If you can promise that every short line begins with 1, then it can be made much simpler.
struct lines
{
string character;
string eightbit_hexbase_number1;
string eightbit_hexbase_number2;
}
ifstream infile("filename");
vector<lines> lineStore;
line tempHoldingLine;
int skip = 0;
while(notYetReachedTheEndOfTheFile) // Work this out yourself :)
{
if (!skip)
{ infile >> tempHoldingLine.character;}
infile >> tempHoldingLine.eightbit_hexbase_number1;
infile >> tempHoldingLine.eightbit_hexbase_number2;
// less than elegant way of dealing with short line
if (tempHoldingLine.eightbit_hexbase_number2.length() == 1)
{
string theNextCharacter = tempHoldingLine.eightbit_hexbase_number2;
tempHoldingLine.eightbit_hexbase_number2 = 0;
skip = 1;
lineStore.push_back(tempHoldingLine);
tempHoldingLine.character = theNextCharacter;
}
else
{
// It was a full line of three
lineStore.push_back(tempHoldingLine);
skip = 0;
}
}
You could use the ifstream class, and use that to read your lines.
1 2 3 4 5 6 7 8 9 10 11
ifstream file = new ifstream("file_name.txt");
//try/catch block should be here, blah blah
while(!file.eof())
{
char * str = file.getline();
//TODO: split the line into multiple strings, delimited by space
//do whatever it is you're supposed to do with them
}
file.close();
To split the string, you could use strtok(str, " "), or the boost library's "split" function.
Can anyone think of a way to read each number/string in and store it so that for example line1 number1=1, number 2=0x00000000 and number3=0?