- 为何参数ostr需要为带上&呢?
- 为何返回ostream&,就可以和cout一块用呢?
ostream & operator<<(ostream& ostr, const list<int> &listInt)
{
for (auto &i : listInt)
{
ostr << " " << i;
}
return ostr;
}
使用方式:
list<int> listInt1 = { 5,9,0,1,3 };
listInt1.sort();
cout << listInt1 << endl;// 0 1 3 5 9