#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
struct Student
{
int no;
int id;
string city;
float points;
int grade;
Student *next;
};
int main()
{
int seq_num, Id, gr;
float pn;
string ct;
ifstream infile;
infile.open("d:\\dataset.txt");
Student *head=NULL;
while (infile)
{
infile>>seq_num>>Id>>ct>>pn>>gr;
Student *newStudent;
newStudent = new Student;
newStudent->no = seq_num;
newStudent->id = Id;
newStudent->city = ct;
newStudent->points = pn;
newStudent->grade = gr;
newStudent->next = NULL;
if (head ==NULL)
head = newStudent;
else
{
newStudent->next = head;
head = newStudent;
}
}
cout<<"\nNo\tID\tCity\tPoints\tGrades ";
cout<<"\n\n";
Student *Display_ptr;
Display_ptr = head;
while (Display_ptr)
{
cout<<Display_ptr->no<<"\t"
<<Display_ptr->id <<"\t"
<<Display_ptr->city<<"\t"
<<Display_ptr->points<<"\t"
<<Display_ptr->grade<<"\t"
<<endl;
Display_ptr = Display_ptr->next;
}
infile.close();
return 0;
}
This code is good and it works. As you can see I need to store each column in different type which is appropriate for it. But now my problem is taht I have another text file, and like this I need to store it but the problem is that in this text file each column is separated with tab, but the length of third column is larger than others. I try to read it with getline() and giving a delimiter but I did'nt succed. I want from to tell me how to use the getline() example: