作者littleshan (我要加入剑道社!)
看板C_and_CPP
标题Re: [问题]跟指标与vector有关的问题
时间Mon Apr 20 10:56:13 2009
※ 引述《luckychild (兑现承诺)》之铭言:
: DEV C++的编译器讯息为
: no match for'operator<<' in 'std::cout << *a'
: 接下来就是一长串note了,不贴上来了.
: 谢谢回覆罗!
因为 vector 并未针对 iostream 有特别的 operator overload
如果你想用 << 来输出 vector 的内容
可以试试下列的方式:
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& array)
{
std::copy(
array.begin(),
array.end(),
std::ostream_iterator<T>(out, ",")
);
return out;
}
int main()
{
std::vector<double> a;
...
...
std::cout << a << std::endl;
...
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 219.87.151.2