why does passing a nullptr value to an ostream stop printing to stdout?

99 views Asked by At
$ g++ --version
g++ (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    
$ g++ test.cpp -o test -g

test.cpp

#include <iostream>

int main() {
  const char * c = nullptr;
  std::cout << "testing: " << c << std::endl;
  std::cout << "why does this not print?" << std::endl;
  return 0;
}

Running test:

$ ./test
testing: $ echo $?
0

It seems like the nullptr prevents further printing to stdout but I'm not sure why. The std::endl does not seem to be processed, and the same thing occurs if I just pass \n instead of std::endl.

0

There are 0 answers