【发布时间】:2019-02-01 05:45:05
【问题描述】:
我在研究结构时遇到了这个问题。
#include<iostream>
#include<string>
#include<vector>
using namespace std;
struct entry
{
string name;
int number;
};
int main()
{
vector<entry> adres{{"Noname",212345},{"Yesname",7564745}};
for(x:adres)
{
cout<<x<<endl;
}
}
这只是一个测试代码!
所以我创建了一个结构并想在我的向量中使用它。 C++ 给了我这个错误
error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'entry')|
经过一番搜索,我发现我需要重载
我的问题是我该怎么做?我怎样才能重载“
【问题讨论】:
-
“这只是一个测试代码!” - 您能否发布代码,仅显示您所询问的问题?
for(x:adres)不是格式良好的循环,会导致完全不相关的错误。请阅读有关创建minimal reproducible example 的更多信息。
标签: c++ operator-overloading operators ostream