gcc/clang "no match for 'operator<<'" in CI
The compiler found no operator<< that accepts the left and right operands. A missing <string>/<iostream> include, or a user type with no stream operator, is the usual cause.
What this error means
Streaming a value to std::cout or an ostringstream fails with "no match for operator<<", often for std::string or a custom type.
clang
log.cpp:8:12: error: no match for 'operator<<' (operand types are 'std::ostream' and 'Point')
8 | std::cout << p;
| ^~Common causes
How to fix it
Provide or include the operator
- Include <string>/<iostream> when streaming standard types.
- For a custom type, define a free operator<< taking std::ostream&.
clang
#include <ostream>
std::ostream& operator<<(std::ostream& os, const Point& p) {
return os << '(' << p.x << ',' << p.y << ')';
}How to prevent it
- Include the header for every streamed standard type and define operator<< for any custom type you print.
Frequently asked questions
What causes ""no match for operator<<""?
Streaming a value to std::cout or an ostringstream fails with "no match for operator<<", often for std::string or a custom type.
How do I fix "no match for operator<<"?
Provide or include the operator
Related guides
gcc/clang "'X' was not declared" needing <filesystem>/<charconv> in CIFix gcc/clang errors for facilities like std::filesystem or std::optional in CI - the modern standard header…
gcc/clang "call of overloaded X is ambiguous" in CIFix gcc/clang "call of overloaded X is ambiguous" in CI - two or more overloads match the arguments equally w…
gcc/clang "narrowing conversion inside { }" in CIFix gcc/clang "narrowing conversion of X inside { }" in CI - brace initialization forbids implicit narrowing…