我的目标是从文件中获取数据,将其拆分并将它们放入一个数组中以供将来修改。
这是数据的样子:
course1-Maths|course1-3215|number-3|professor-Mark
sam|scott|12|H|3.4|1/11/1991|3/15/2012
john|rummer|12|A|3|1/11/1982|7/15/2004
sammy|brown|12|C|2.4|1/11/1991|4/12/2006
end_Roster1|
我想把数学、3215、3 和 Mark 放入一个数组中,然后 sam scott 12 H 3.4 1/11/1991 3/15/2012。
这是我到目前为止所拥有的:
infile.open("file.txt", fstream::in | fstream::out | fstream::app);
while(!infile.eof())
{
while ( getline(infile, line, '-') )
{
if ( getline(infile, line, '|') )
{
r = new data;
r->setRcourse_name(line);
r->setRcourse_code(3);//error not a string
r->setRcredit(3);//error not a string pre filled
r->setRinstructor(line);
cout << line << endl;
}
}
}
然后我试图查看它没有存储任何内容。