. Advertisement .
..3..
. Advertisement .
..4..
Hi developer experts,
I have a small but frustrating use case, and so far, I couldn’t get my head around this problem & ideal solution. I am running my command and facing one problem with the no operator “<<" matches these operands visual c++.
Below is the command I used:
void Student::getCoursesEnrolled(const vector<Course>& c)
{
for (int i = 0; i < c.size(); i++)
{
cout << c[i] << endl;
}
}
When I run it, I get the following error:
Error: No operator matches these operands
operand types are: std::ostream << const Course
I am looking forward to gaining some knowledge from all experts.
Thank you, guys!
The cause: The issue is that operator isn’t an overload for the kind of Course objects you’re trying to produce in your statement below. This causes the error “no operator “<<” matches these operands visual c++”.
Solution: You must overload this operator or create your own function to output an object of type Course in
std::ostream
. For example, consider the following is a classCourse
definition.When you are able to write
You’re not quite right. You are trying to print this using
cout
.cout
doesn’t know how to printCourse
objects unless you give it an overloadedoperator<<
.For more information, see the operator overloading bible on StackOverflow.