C++ 如何为vector重载ostream(<;<;)(打印vector中的所有集合)

C++ 如何为vector重载ostream(<;<;)(打印vector中的所有集合),c++,vector,C++,Vector,我不知道如何从vector打印所有信息,以及如何调用重载ostream?你能帮忙吗 template<class T> class MainVector { ... ... }; ostream &operator<<(ostream &os, const MainVector<T> &vect) { /* Code here down */ } 模板 类主向量{ ... ... }; 下面的ostream&operator是一个典

我不知道如何从vector打印所有信息,以及如何调用重载ostream?你能帮忙吗

template<class T>
class MainVector {
...
...
};
ostream &operator<<(ostream &os, const MainVector<T> &vect) {
/*
 Code here down
*/
}
模板
类主向量{
...
...
};

下面的ostream&operator是一个典型的模板,可用于向量的格式化输出:

template<class T>
ostream& operator<<(ostream& stream, const std::vector<T>& values)
{
    stream << "[ ";
    copy( begin(values), end(values), ostream_iterator<T>(stream, " ") );
    stream << ']';
    return stream;
}
模板

下面的ostream&operator是一个典型的模板,可用于向量的格式化输出:

template<class T>
ostream& operator<<(ostream& stream, const std::vector<T>& values)
{
    stream << "[ ";
    copy( begin(values), end(values), ostream_iterator<T>(stream, " ") );
    stream << ']';
    return stream;
}
模板
ostream&运算符
模板
std::ostream&操作员
模板
std::ostream和操作员
std::cout << AnInstanceOfMainVector << '\n';