template<typename T>
ostream& operator << ( ostream& ot,vector<T> const& v)
{
ot << "{";
for (size_t i = 0; i < v.size(); ++i)
{
ot << v[i];
if (i != v.size() - 1)
{
ot << ",";
}
}
ot << "}";
return ot;
}
int main()
{
vector<int> a = { 1,2,3,4,5 };
cout << a << endl;
vector<string> b = { "ok","fun","hello"};
cout << b << endl;
return 0;
}
在重载输入输出流时,为什么输入输出流要放在前面,如上面ot,如果ot和容器位置调换,则重载不成功会报错