本文介绍了C ++是否可以删除整个向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找出一个向量.不只是它的一个元素,而是整个事情.例如std :: cout<<vectorName;那样的东西,希望有道理.有任何想法吗?预先感谢
I need to cout a vector. Not just an element of it, but the whole thing.For example std::cout << vectorName;Something like that, hope it makes sense.Any ideas?Thanks in advance
推荐答案
您可以定义实用程序函数,如
You can either define a utility function like
template <typename T>
ostream& operator<<(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;
}
这篇关于C ++是否可以删除整个向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!