Skip to main content
ai-slop/cpp-endl-in-streammanual fix

std::endl in a stream.

`<< std::endl` used as a newline. It also flushes the stream every time, which is costly in loops and file output.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

cpp-endl-in-stream.cpp
✗ Flagged
void write_report(std::ostream& out, const std::vector<Row>& rows) {
    for (const auto& row : rows) {
        out << row.name << ',' << row.total << std::endl;
    }
}
Why this trips

Deterministic line match: flags `<< std::endl` in C++ files, outside comments and strings.

cpp-endl-in-stream.cpp
✓ Clean
void write_report(std::ostream& out, const std::vector<Row>& rows) {
    for (const auto& row : rows) {
        out << row.name << ',' << row.total << '\n';
    }
    out.flush();
}
What changed

Write `'\n'`, and flush explicitly with `std::flush` only where output must appear immediately.

Tutorial code ends every line with `std::endl`, so agents do too, without needing the flush.

How this rule is justified.

Rule id

ai-slop/cpp-endl-in-stream

Enforcing engine

ai-slop

Detector strategy

Deterministic line match: flags `<< std::endl` in C++ files, outside comments and strings.

Legitimate code that is NOT flagged

`'\n'` newlines, explicit `std::flush`, unqualified `endl`, and `.c`/`.h` files are not flagged.

Evidence

Part of aislop's C/C++ rule set. C/C++ support, including C/C++-specific AI-slop rules, arrived in aislop v0.14.1.