Can someone please explain how to fix the glitch i am experiencing? i dont understand why its occurring however i am fairly new to c++.
The function is supposed read back each line of a .txt file and store the value of the line into a string "D", and then the data of that string is then assigned to integers. then set the string back to have no value then its supposed to go read the next line.
however after the file is loaded i check the values of the integers and every single one is shown as being 0. i have verified my file being read does have the right have the correct values in it which are greater then 0. the glitch the load function is not reading those values right and i have no clue why.
i have the code typed right according to the references i have checked on this website.
everything other then it not reading the values in the file right works correctly for me how i want it to.
#include "Lib.h"
#include <fstream>
usingnamespace std;
#include <sstream>
usingnamespace std;
string D;
void Load()
{
//figuring out what file to load
cout << "\n\nWhat Is The Name Of the Character You Would Like to Play?";
cin >> Name;
cout << "\n\nWhat Save File Of " << Name << " Would You Like To Play?";
cin >> choice;
cout << "\n\n";
A << choice;
B = A.str();
C = ".txt";
filename = Name + B + C;
ifstream inputFile;
inputFile.open(filename.c_str());
cout << "Loading is at 0 %";
//Assigning the values stored back to the character
//We ignore this first line of the file because it is just the name of the character which the player just input a few seconds ago
istream& getline ( istream& inputfile, string& D );;
//the 2nd line is the amount of times the character was saved
istream& getline ( istream& inputfile, string& D );
Saved = 0 + 0 + atoi(D.c_str());
D = "";
}
this is just a snippet from the function. i did not put the whole function because its around 460 lines and reads back over 90 integers and also because i did notice every single integer got assigned 0 as a value. they are all typed the exact same way which is
1 2 3
istream& getline ( istream& inputfile, string& D );
Saved = 0 + 0 + atoi(D.c_str());
D = "";
except the name of the integer gets changed each time
The code you copied from that reference you use is just code that shows the declaration of those functions, it's not how you should actually be using the functions. Function usages are generally in examples, or you can deduce it yourself if you understand what you are doing.