Monday, May 14, 2012

trying to read a text file data into an array to be manipulated then spit back out

My aim is to take the data from the file, split it up and place them into an array for future modification.



The is what the data looks like:



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|


I want to take maths, 3215, 3 and Mark and put into an array,
then sam scott 12 H 3.4 1/11/1991 3/15/2012.



This is what I have so far:



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;
}
}
}


Then I tried to view it nothing is stored.





No comments:

Post a Comment