I am having issues with loading the string "Dirty T-Shirt" from a text file i use to save my game with.
When I load it, it splits it up. Like (torso : Dirty, Hands : T-shirt) it should be (torso : Dirty T-shirt). I thought I heard using cin to set a string variable like this will cause issues like this. The thing is I initialize the game with the variable "Torso" set to "Dirty T-shirt". I never actually input it using cin.
I believe whenever you use your current method of reading from a file, it reads the line until it hits a space (hence the splitting of your dirty tshirt).
ifstream inputFile("save.txt");
string str = "";
getline(inputFile, str);
// now str contains the value of the whole line
Basically, replace all of your current lines with getline(). getline(inputFile, wallet); // etc
-------------------------------------
Also, just a side note, your current method of loading data is effective for your small game as it exists currently, but when games get bigger you can't afford to write a whole line of code to load in every single value needed. It is much more effective to write a loop to read in all the values.
A loop like so would read the whole file:
1 2 3 4 5 6 7 8 9
// while not end of file
while (!inputFile.eof())
{
string str = "";
getline(inputFile, str);
// then come up with a fancy way of storing
// your data to make it efficient
}
We could get into data model stuff, but thats beyond the scope of your question. I don't want to get carried away. Haha. Let me know if you need anymore help.
ok, so getline worked for spliting the strings up. but when i load now the items that were getting split up are all in the wrong order, almost like the were loaded in the wrong sequence...
kind of hard to explain but it should look like
head [dirty bb cap]
torso [dirty tshirt]
legs [dity jeans]
hands [nothing]
feet [old sneakers]
holding [nothing][nothing]
gadget [nothing]
but instead ...
head [nothing]
torso [dirty bb cap]
legs [dirty tshirt]
hands [dirty jeans]
feet [nothing]
holding [old sneakers][nothing]
gadget []<<no string
i checked the save and load orders to make they were the same. (see initial post)
also, when trying to write into my two array's they come back completely empty.