0

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

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by mitrious
0

Sorry ... I just mistyped something ... it works fine now ... thx tho ...
while(in, x) << I typed , instead of >> ... that's why it wasn't working ...

lol ... I realized that just after I posted here ...

thx tho!

btw Info is the struct I defined gerard ... so record is a struct of Info type.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.