I am creating a bank terminal for an assignment. It has the ability to add clients with each client containing 5 different variables for name, address, social#, employer, and income. Those variables are then written to a file once they have been filled and the terminal is exited.
The problem I am having is when starting the terminal I need to read these values from the file, each on their separate lines and store them in their respective variables to use in the addClient() function. This is the code snippet to make things easier than submitted my entire project:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
using namespace std;
std::ifstream infile2("client-info.txt");
//Strings used for respective items from file
string clientName, clientAddress, clientSocial, clientEmployer, clientIncome;
//Here is where I am having the problem of reading the info from the file
//line by line and storing it in respective variables.
while (infile2)
{
getline(infile2,clientName);
getline(infile2,clientAddress);
getline(infile2,clientSocial);
getline(infile2,clientEmployer);
getline(infile2,clientIncome);
client.addClient(clientName, clientAddress, clientSocial, clientEmployer, clientIncome);
}
infile2.close();
}
The file, for example is stored as such.
John Doe
123 Easy Lane
123-45-6789
USSRC
36000
The problem I am having is that I cannot figure out a solid way to get each line and store them in their respective strings. For the assignment, I will not have to be dealing with blank spaces and such. So lines 0-4 will be for one client, 5-9 for another, etc.
A push in the right direction would be greatly appreciated, thanks!