First, I'm sorry if code is sloppy or wrong. I am having a hard time with c++.
I am trying to create a customer from a file and save each customer as the object customer and store each of the variables.
I have successfully been able to open and read the file save the words to a vector. I now need to create a customer and save the information.
My Question is - Now that I have a vector with all of the information how would I create a new customer and store the first item in vector as fName, second as lName, and the third as acctNumber. The 4th item in the vector would be a new customer saving as their fName and so on.
An example of the text file I am using is below.
Michael Jackson 1
George Jones 2
Brittany Spears 3
Goal: Above file would instantiate 3 customers and set each of their fName, lName and acctNumber for later use.
class CustomerType {
public:
CustomerType(string f, string l, int a);
string fName;
string lName;
int acctNumber;
videoType chkdOut;
private:
};
CustomerType::CustomerType(string f, string l, int a) {
fName = f;
lName = l;
acctNumber = a;
}
void createCustomer() {
vector<string> myVector;
ifstream myfile;
myfile.open("custDat.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
string tempString;
getline(myfile, tempString);
istringstream iss(tempString);
string word;
while (iss >> word) {
myVector.push_back(word);
}
}
myfile.close();
}
else
cout << "Can't open file" << endl;
}