C++ C++;有可能计算出一个完整的向量吗?

C++ C++;有可能计算出一个完整的向量吗?,c++,vector,C++,Vector,我需要一个向量。不仅仅是其中的一部分,而是整个事情。 例如,std::cout您可以定义一个实用函数,如 template <typename T> ostream& operator<<(ostream& output, std::vector<T> const& values) { for (auto const& value : values) { output << value

我需要一个向量。不仅仅是其中的一部分,而是整个事情。
例如,std::cout您可以定义一个实用函数,如

template <typename T>
ostream& operator<<(ostream& output, std::vector<T> const& values)
{
    for (auto const& value : values)
    {
        output << value << std::endl;
    }
    return output;
}
模板

ostream&operator是的,这是可能的-如果你定义operator
std::copy
是你的朋友。似乎相关:@UlrichEckhardt神号
std::copy(v.begin(),v.end(),std::ostream_迭代器(std::cout,”)
for (auto const& value : values)
{
    std::cout << value << std::endl;
}
template <class T>
std::ostream& operator<<(ostream& out, const std::vector<T>& container) {
   out << "Container dump begins: ";
   std::copy(container.cbegin(), container.cend(), std::ostream_iterator<T>(" ", out));
   out << "\n";
   return out;
}