outputstream - When to use cerr and and when cout in C++? -
i looking illustration differentiates between cerr , cout in c++ ? when need utilize cerr ?
quite user of programme interested in results, because these printed stdout, instance, if utilize unix command cat, eg:
$ cat file.txt
you're expecting file.txt contents appear on stdout. however, if happens during execution of cat (strictly theoretically speaking, nil has ever happenned me), you'd expect go stderr, thus, user, you're still able separate two, eg:
$ cat file.txt 1>result.txt 2>stderr.txt
suppose want collect contents of multiple files, following
$ cat *.java 1>all_files_conent.java 2>errors.txt
in case of files isn't accessible (eg. because of permissions), errors.txt have appropriate message:
cat: controller.java: permission denied
but contents of all_files_content.java right can be.
therefore, if message actual product of program, should utilize cout, if it's status message, utilize cerr. of course, doesn't matter much if goes console byproduct. however, might still want allow user separate two, in illustration above.
c++ outputstream cout
No comments:
Post a Comment