I'm working on an address book application, and the portion I'm really struggling with is getting text from a .txt file and assigning the correct variable to each piece of text. each piece is delineated with a tab.
I'm really struggling with this one. First off, I'm not sure if my logic is 100% sound on my approach, but nevertheless, this is how it's cropped up in my head.
What I'd like to do is run a loop that looks at the text line by line, each line being assigned to its respective variable.
I know my current code isn't right, and the logic isn't fully fleshed out, but this is what I have.
EDIT: I forgot to mention the other variables and their respective datatypes. first name, last name, birth month/day/year, address, city, state, zip/postal code, phone number. they're virtually all strings with the exception of the birth month/day/year and zip code/postal code which are integers.
EDIT** the text file goes something like this
Joe Shmoe 1 1 1980 123Main Capital CA 90210 123-456-7890
Jane Doe 2 5 1960 321Elm Boise ID 12345 987-654-3210
so on and so forth. What I need to do is read through the text file and fill the array elements for each attribute (first, last, month, day, year, address, city, state, zip, phone)
void extPersonType::getInfo()
{
readFile.open("input.txt",ios::in);
if (readFile.is_open())
{
while (readFile.good())
{
for (int i = 0; !readFile.eof(); i++)
{
getline(readFile,lines[i]);
personInfo[i].setFirstName(lines[i]);//change this
cout << personInfo[i].getFirstName();
}
}
readFile.close();
}
If you could help me out on this I'd appreciate it.