Ive tackled every solution I could thing of, but I just cant beat it.
My problem is that the ifstream does not load a file when the file exist in the same folder. For instance, if I had a file named Alexstt.txt in the same folder, and I tried to load it with this program to extract the 3 integers (goldCoins, ironOre, and pickaxes) and display the name, it fails to load it. It goes right along to the else statement.
string getName()
{
string inputName;
cout << "What is your characters name?" << endl;
cin.ignore(); //This line is a problem - remove it
getline(cin, inputName);
return inputName;
}
I removed it and recompiled it. When I played it, after I entered the name, it crashed. This portion of a program is actually part of a larger program, but on this test program it would crash without the cin.ignore(); and on the larger program, it crashes with the cin.ignore();, but with it, it doesn't print my lines of stats.
It's probably the way you are loading from the file:
I used an empty file for the test - you are reading your file - but the way this part
is written
1 2 3 4 5 6 7 8 9 10 11 12 13
int stats[2]; //stats only has array index of 0 and 1
int i = 0;
while(!getld.eof())
{
//probably got an array out of bound write somewhere here
getld >> stats[i];
i++;
}
goldCoins = stats[0];
ironOre = stats[1];
pickaxes = stats[2];//error - array out of bounds read access
playerName = loadPlayerName;
Ahh yes, I see, Ill change it to a vector and see how I can make it more efficient and safe. But my file does have 3 integers in it. Ill post my save codes.
Oh wow, thanks for the help! I wasnt too sure about arrays and I though array[2] would mean 3 allocation slots, 0, 1, and 2. I was also a bit iffy on ifstream and the fact that it goes down the line just went over my head. Works like a charm.