Honestly, I'm not sure what's happening. I put together a program using bits of your code, compiled it using clang, and tried a few different test cases, and I couldn't reproduce your error.
Old habit of forgetting to use std::clog, which by default on Unixes redirects to the same place as std::cerr anyway.
Generally, I use STDERR for diagnostics/errors/messages/indications of the program's status and requests for user input. Why? To keep STDOUT free for the exclusive output of processed data that the user (usually me) might be interested in manipulating further.
I suppose I could have used std::cout here. But meh.