← Back to archive

Stdle #169 · strings · 2026-11-22

What does this C++ snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

#include <iostream>
#include <string>
int main() {
std::string s = "a,b,c";
size_t n = 0;
for (char c : s) if (c == ',') n++;
std::cout << n << "\n";
}
Strings
4 attempts left

Answer & explanation