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

What is

Info record;

what exactly do you mean by "it doesn't work"? Compiler errors? If yes, then what are they ?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.