我需要计算一个向量。不仅仅是它的一个元素,而是整个事情。例如 std::cout << vectorName; 类似的东西,希望它是有道理的。有任何想法吗?提前致谢
您可以定义一个效用函数,如
template <typename T>
std::ostream& operator<<(std::ostream& output, std::vector<T> const& values)
{
    for (auto const& value : values)
    {
        output << value << std::endl;
    }
    return output;
}
或者自己迭代
for (auto const& value : values)
{
    std::cout << value << std::endl;
}