How to disable cout output in the runtime?

Sure, you can (example here):

int main() {
    std::cout << "First message" << std::endl;

    std::cout.setstate(std::ios_base::failbit);
    std::cout << "Second message" << std::endl;

    std::cout.clear();
    std::cout << "Last message" << std::endl;

    return 0;
}

Outputs:

First message
Last message

This is because putting the stream in fail state will make it silently discard any output, until the failbit is cleared.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)