【发布时间】:2022-01-28 11:55:13
【问题描述】:
我不知道为什么要在 c++ 中重叠 std::array 的 ostream。 (错误:'operator
#include <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator <<(ostream& out, T& arr)
{
bool pre = false;
for(auto& i : arr)
{
if(pre) out << ' ';
pre = true;
out << i;
}
return out;
}
signed main()
{
array<int, 4> a = {123, 123, 12, 12};
cout << a << "\n";
return 0;
}
【问题讨论】:
-
错误指向
<< "\n"部分。我猜你需要#include <iostream> -
我试过了,但是没用
-
你提供了
operator<<,它可以接受任何东西。这使得operator<<的所有标准库重载都模棱两可 -
感谢您的回复
-
我们有什么替代措施来解决这个问题吗?