I have a file format for storing text of any sort. It's a file format from a company, so I can't change it.
Basically, in the beginning of the file, a series of "string starts on char#", "string length equals" values determines the "address" where a string starts and how many chars I shall count to get it. (There's a whole document to explain it; I've attached it to the message).
Something like this:
0 4
4 4
8 9
BirdBookTelephone
So, "Bird" starts on position 0 and has 4 chars; "Book" starts on position 4 and has 4 chars; "Telephone" starts on position 8 and has 9 chars; and so on.
Positions and lengths are stored in binary format, so when you open the file, you can't read them.
To "translate" them, I use the following function:
inline dWord string2Int(string str) // dWord == unsigned int
{
return *reinterpret_cast<dWord*>(const_cast<char*>(str.data()));
}
That works TO READ the values from a given string. But now I have to do the opposite: change a readable int, turn it into binary little-endian and return the value as a string.
inline string int2String(dWord n)
{
return ?????????????;
}
How do I do that????