I have a txt file with a list of records for example:
John Swift 15 2005 20000
Andrew Smith 25 2001 25000
I am trying to read in this data into a linked list of data structures as follows:
The problem I'm having is that as I have shown in the text file, the name has a whitespace in between name and surname.
I'm not very good with input / output and strings. Could someone please give me an idea as to how to enter both name and surname from the file into one variable in the structure of the linked list.
I think the getline command has to be used:
I don't know how to set up delimiters to do this... any help greatly appreciated
Thx!
John Swift 15 2005 20000
Andrew Smith 25 2001 25000
I am trying to read in this data into a linked list of data structures as follows:
Code:
temp = new client;
head = temp;
//do
while(!infile.eof())
{
infile >> temp->name;
infile >> temp->experience;
infile >> temp->year;
infile >> temp->desiredsalary;
temp->next = new client;
temp = temp->next
}
temp->next = NULL; // set last next in the linked list to NULL
temp = head; // move temp pointer to start of the list
}
I'm not very good with input / output and strings. Could someone please give me an idea as to how to enter both name and surname from the file into one variable in the structure of the linked list.
I think the getline command has to be used:
Code:
infile.getline (name);
Thx!
Comment