istream& operator>>(istream& stream, list<monom>& pol)
{
char z1,z2;
monom m;
stream >> noskipws;
while(stream >> m.a >> z1 >> z2 >> m.i) {
if (z1!=’x’ || z2!=’^’) {
stream.setstate(ios::failbit);
break;
}
pol.push_back(m);
// This is where I do not understand why stream >> z1
if (stream.peek()==’\n’) {
stream >> z1;
break;
}
}
pol.sort();
pol.remove(null);
return stream;
}
我有一个类monom,想要重载>>包含monom. 看着代码我明白了一切
if (stream.peek()==’\n’) {
stream >> z1;
break;
}
我知道stream.peek()看下一个空格,如果它是空的(== \n)那么为什么要它stream >> z1,这让我感到困惑。