Re: [問題]跟指標與vector有關的問題
看板C_and_CPP (C/C++)作者littleshan (我要加入劍道社!)時間16年前 (2009/04/20 10:56)推噓0(0推 0噓 0→)留言0則, 0人參與討論串2/2 (看更多)
※ 引述《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
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章