Hello, I'm working on a text-based game, but I'm having some trouble with importing some data from a textfile...
for some reason it all works fine without spaces, but if I incclude a space in the name(in the textfile) it just breaks...
any help?
1 2 3 4 5 6 7 8 9 10 11
string chardat = charload();
int namelength;
(stringstream)chardat.substr(0, 2) >> namelength;
string name = "";
name = chardat.substr(5, namelength);
int strength;
(stringstream)chardat.substr(8 + namelength, 2) >> strength;
int speed;
(stringstream)chardat.substr(13 + namelength, 2) >> speed;
int HP;
(stringstream)chardat.substr(18 + namelength, 2) >> HP;
You will need to show more of the code for us to help. How about showing charload() and also show where chardat is saved. And anywhere namelength is calculated would be nice too.
the problem with that would be that the length of chardat.txt is variable, because the length of the name differs per user(different users enter different names)...