前提
C++を学校で学んでいます。以下のコードが理解できず行き詰っています。
該当のソースコード
#include <iostream> #include <fstream> #include <sstream> using namespace std; typedef struct student{ string name; string id; double gpa; struct student* next; }Student; int main(){ ifstream ifs("data3.csv"); string line; stringstream stream; Student *top = NULL; Student *sp; while(getline(ifs, line)){ sp = new Student; sp->next = top; top = sp; stream.clear(); stream << line; getline(stream,sp->name,','); getline(stream,sp->id,','); stream >> sp->gpa; } sp = top; while(sp != NULL){ cout << sp->name << "," << sp->id <<"," << sp->gpa << endl; sp = sp->next; } ifs.close(); }
data3.csv
まるた まるお,00k0000,3.25
かくた かくこ,00k0001,2.84
てんだ てんこ,00k0002,3.01
一個目のwhile文が何をどうしているのか理解ができません。
特にtop = sp; はなぜいるのでしょうか
