Skip to content
Latchkey

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

  1. Include <string>/<iostream> when streaming standard types.
  2. 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

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card