C++ 过载<&书信电报;操作员打印出std::列表

C++ 过载<&书信电报;操作员打印出std::列表,c++,list,iterator,std,C++,List,Iterator,Std,我一直在尝试实现重载的曲线是常量限定的,因此curve.points是常量限定的,而curve.points.begin()返回一个std::list::const_迭代器,而不是std::list::iterator 容器有两个begin()和end()成员函数:一对不是常量限定的成员函数,返回iterators,另一对是常量限定的,返回const\u iterators。通过这种方式,您可以迭代非常量的容器并读取和修改其中的元素,但也可以迭代具有只读访问权限的常量容器。或 您可以使用std:

我一直在尝试实现重载的
曲线
是常量限定的,因此
curve.points
是常量限定的,而
curve.points.begin()
返回一个
std::list::const_迭代器
,而不是
std::list::iterator

容器有两个
begin()
end()
成员函数:一对不是常量限定的成员函数,返回
iterator
s,另一对是常量限定的,返回
const\u iterator
s。通过这种方式,您可以迭代非常量的容器并读取和修改其中的元素,但也可以迭代具有只读访问权限的常量容器。

您可以使用
std::copy
作为:

std::copy(points.begin(), points.end(), 
                      std::ostream_iterator<Point>(outStream, "\n"));
复制(points.begin(),points.end(), std::ostream_迭代器(扩展,“\n”);
确保
operator的签名不知道你是如何尽快回复的,但你完全正确,这解决了我的问题。我想这突出了我对std库的理解不足,但我会继续攻克。。。谢谢您可以尝试一下:-)
ostream& operator<<( ostream &out, const NURBScurve &curve)
{
 out << "Control points: " << endl;
 list<Point>::iterator it;
 for (it = curve.points.begin(); it != curve.points.end(); it++)
    out << *it; 
 out << endl;
 return out;
}
no match for ‘operator=’ in ‘it = curve->NURBScurve::points. std::list<_Tp, _Alloc>::begin [with _Tp = Point, _Alloc = std::allocator<Point>]()’
/usr/include/c++/4.2.1/bits/stl_list.h:113: note: candidates are: std::_List_iterator<Point>& std::_List_iterator<Point>::operator=(const std::_List_iterator<Point>&)
std::copy(points.begin(), points.end(), 
                      std::ostream_iterator<Point>(outStream, "\n"));
std::ostream & operator <<(std::ostream &out, const Point &pt);
                                            //^^^^^ note this