I wrote these functions and when I call them they're not working ... and I don't know why.
here is the code for the functions
istream& read_notes(istream& in, vector<double>& nt)
{
if(in){
nt.clear();
double x;
while(in, x){
nt.push_back(x);
}
in.clear();
}
return in;
}
istream& read_info(istream& is, Info& inf)
{
is >> inf.name;
read_notes(is, inf.notes);
is.clear();
return is;
}
here's the program:
int main()
{
vector<Info> Data;
typedef vector<Info>::size_type vc_sz;
Info record;
string::size_type maxlen;
cout << "Enter the names and the notes: ";
while(read_info(cin, record)){
Data.push_back(record);
}
sort(Data.begin(), Data.end(), compare);
vc_sz size = Data.size();
return 0;
}
I used a struct with string name and vector<double> notes
The thing is ... if I try to compute only the names it works, could someone tell me what I'm doing wrong ... I compared it to one of the examples in the book ... and it looks right ...
THX