I was studying structures and came across this problem.
#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;
}
}
This is just a test code!
SO I created a struct and wanted to use that in my vector. C++ gave me this error
error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'entry')|
After some searching I found that I needed to Overload << operator to output my Vector with my defined data type.
My question is how can I do that? How can I overload " << " so that I can output my vector. I know the concepts of Operator Overloading but this one just seems too confusing. Is there any way I can just use " << " sign to output for user defined types?