I'm working on a project using C++, and I was asked to read a txt file and assign the data to a node. The text file is:
Yani, 19, 1993, 12345
Oscar, 20, 1994, 56789
And I have the struct List:
struct List{
string name;
int age;
int birth;
int id;
List *next;
List *prev;
}
My question, how can I assign the data from the text file to the nodes, in this case, two nodes, but if there are more lines, it has to create more new nodes?
Part of my code I'm using:
#include <fstream>
struct List{
...
}
//Here I create the first Node and:
aux=head;
ifstream file ("file.txt");
file >> aux->name >> aux->age >> aux->birth >> aux-> id;
If the text file would not have the commas in it, works perfectly, but the commas make errors everywhere.
Also, to conclude :) If the text file has:
Danny Watson, 23, 1980, 58953
The name of the node must be Danny Watson, not only Danny :)
I hope you can help me! I'll be so grateful.
(Sorry, my English is not that good :( )