have had a structure with defines an x and y coordinate, as well as a 20-character name.
When reading in from the packfile, I would simply use:
|3|| int x;|
|4|| int y;|
|5|| char name;|
|8||itemType loadData(PACKFILE *f)|
|10|| itemType newItem;|
|12|| pack_fread(newItem.name, sizeof(newItem.name), f);|
|13|| newItem.x = pack_igetw(f);|
|14|| newItem.y = pack_igetw(f);|
|16|| return newItem;|
However, I want to change the name from a character to a std::string. If I try to use the same routine, I'll have problems, since the size of the name will be different for each name.
Is there an alternate method I could use to read in an unknown-sized string variable with pack_fread?
One thought I had considered was something similar to std::cin.get(char c). It would only grab a single letter at a time, until it hit a '\0'. Or, if I specify a string-type to pack_fread, will it be able to keep reading in data until it finds the '\0' itself?
Unfortunately, pack_fread didn't seem to have any "Similar topics" on the page that I could check out...
Thanks if anyone knows!