I need to use the function getline to be able to read in the spaces within a string. Currently, I'm reading word by word and any space will input the next word into a different variable. A small extract of the code is as below.
istream & operator >>( istream & input, Unit & C )
{
input >> C.unID >> C.unName >> C.credits >> C.Result >> C.mDay >> C.mMonth >> C.mYear;
return input;
}
ostream & operator <<( ostream & os, const Unit & C )
{
os << " Unit ID: " << C.unID << '\n';
os << " Unit Name: " << C.unName << '\n'
<< " Credits: " << C.credits << '\n'
<< " Result: " << C.Result << " marks" << '\n'
<< " Date: " << C.mDay << " " << C.mMonth << " " << C.mYear << '\n';
return os;
}
Note that I only need getline for unName.
As for the infile, it's in my main.cpp. Code are as below.
ifstream infile( "rinput.txt" );
if( !infile ) return -1;
Student R;
infile >> R;
ofstream ofile( "routput.txt" );
ofile << R
<< "Number of units = " << R.GetCount() << '\n'
<< "Total credits = " << R.GetCredits() << '\n';
The code works fine and all.