I am trying to write code for a program that reads from a text file that has 50 phone numbers and names. The format is number, first name(s), last name.
ex)
2942893
Bill Scott
Jones
3823920578
Mark Thomas
Sorensen
2931093489
John
Hansen
I am supposed to store the phone number and full name each in their own string (no using c-strings). I am then supposed to print the information to the screen in the following format: last name (in alphabetical order using selectionSort), first name(s), phone number (with hyphens).
ex)
Hansen, John 293-109-3489
Jones, Bill Scott 294-2893
Sorensen, Mark Thomas 382-392-0578
I have successfully opened the file but am confused on how to do the rest of the code. I know it is supposed to be simple, but I a missed the last couple of days of class because I am sick so I have no idea what I am doing.
Thanks for your help.
std::getline to read a string.
store them in std::vector. It would be good if you wrote a struct to hold the three strings.
cout << str to print a string.
I'll leave the dashes for you to figure out yourself..
We are only allowed to use code that we learned in class, and we haven't talked about vectors or structs. So I can't use those. If I named two strings (string name; and string phoneNumber;) would I use getline to read both the number and name in? And how do I read in both lines of the name?
This is what I have so far. But when I try to print the numbers to the screen, it is just printing out every other line. I need the name string to have the second and third lines while the phoneNumber string has all of the numbers.
one entry takes 3 lines, so you need to have 3 arrays and 3 getline()s.
by the way, getline() removes then '\n' from the stream, so you don't need to ingore() anything.