console.h

This file redirects the cin, cout, and cerr channels to use a console window. This file must be included in the source file that contains the main function, although it may be included in other source files as well.
Functions
clearConsole() Erases the contents of the console window.
getConsoleEcho() Returns whether console output is also sent to the plain text console.
getConsoleExitProgramOnClose() Returns whether console should shut down the entire program when it is closed.
getConsolePrintExceptions() Returns whether console should catch and display exceptions that occur when the program is running.
setConsoleEcho(echo) Changes whether console output is also sent to the plain text console.
setConsoleExitProgramOnClose() Changes whether console should shut down the entire program when it is closed.
setConsoleFont(font) Changes the font used for the console.
setConsoleLocation(xy) Changes the x/y position of the console on screen.
setConsolePrintExceptions() Changes whether console should catch and display exceptions that occur when the program is running.
setConsoleSize(widthheight) Changes the size of the console to the specified dimensions, measured in pixels.
setConsoleWindowTitle(title) Changes the title bar text of the console window to the specified text.

Function detail


void clearConsole();
Erases the contents of the console window.

Usage:

clearConsole();

bool getConsoleEcho();
Returns whether console output is also sent to the plain text console. The Stanford graphical console window takes over the standard output streams cin, cout, and cerr, but the old plain-text versions are still available, usually as a pane at the bottom of your development environment (IDE). If the console echo is true, any messages sent to the graphical console are also sent to the old plain text console. This is generally used to assist in capturing or comparing output.

The console echo is initially false but can be changed to true by calling setConsoleEcho and/or by defining the compiler flag SPL_CONSOLE_ECHO.

Usage:

bool echo = getConsoleEcho();

Available since: 2014/02/01 version of C++ library


bool getConsoleExitProgramOnClose();
Returns whether console should shut down the entire program when it is closed.

This value is initially false but can be changed to true by calling setConsoleExitProgramOnClose and/or by defining the compiler flag SPL_CONSOLE_EXIT_ON_CLOSE.

Usage:

bool exit = getConsoleExitProgramOnClose();

Available since: 2014/02/01 version of C++ library


bool getConsolePrintExceptions();
Returns whether console should catch and display exceptions that occur when the program is running. If true, the console enables a top-level terminate signal handler that will catch and display any exception that is about to otherwise terminate the program. Information about the exception will be emitted to cerr. This is typically useful for new programmers to help them diagnose the cause of a program crash. The same information could be gathered by running the program in a debugger, but many new programmers are not experienced with the debugger or are unwilling to use it, so this feature provides a middle ground.

This value is initially false but can be changed to true by calling setConsolePrintExceptions and/or by defining the compiler flag SPL_CONSOLE_PRINT_EXCEPTIONS.

Usage:

bool exit = getConsolePrintExceptions();

Available since: 2014/02/01 version of C++ library


void setConsoleEcho(bool echo);
Changes whether console output is also sent to the plain text console. The Stanford graphical console window takes over the standard output streams cin, cout, and cerr, but the old plain-text versions are still available, usually as a pane at the bottom of your development environment (IDE). If the console echo is true, any messages sent to the graphical console are also sent to the old plain text console. This is generally used to assist in capturing or comparing output.

The console echo is initially false but can be changed to true by calling this function and/or by defining the compiler flag SPL_CONSOLE_ECHO.

Usage:

setConsoleEcho(echo);

Available since: 2014/02/01 version of C++ library


void setConsoleExitProgramOnClose(bool exit);
Changes whether console should shut down the entire program when it is closed.

This value is initially false but can be changed to true by calling this function and/or by defining the compiler flag SPL_CONSOLE_EXIT_ON_CLOSE.

Usage:

setConsoleExitProgramOnClose(exit);

Available since: 2014/02/01 version of C++ library


void setConsoleFont(const string& font);
Changes the font used for the console. The font parameter is typically a string in the form family-style-size. In this string, family is the name of the font family; style is either missing (indicating a plain font) or one of the strings Bold, Italic, or BoldItalic; and size is an integer indicating the point size. If any of these components is specified as an asterisk, the existing value is retained. The font parameter can also be a sequence of such specifications separated by semicolons, in which case the first available font on the system is used.

Usage:

setConsoleFont(font);

void setConsoleLocation(int x, int y);
Changes the top/left corner of the console window to be located at the specified (x, y) pixel position.

Usage:

setConsoleLocation(x, y);

Available since: 2014/02/01 version of C++ library


void setConsolePrintExceptions(bool print);
Changes whether console should catch and display exceptions that occur when the program is running. If true, the console enables a top-level terminate signal handler that will catch and display any exception that is about to otherwise terminate the program. Information about the exception will be emitted to cerr. This is typically useful for new programmers to help them diagnose the cause of a program crash. The same information could be gathered by running the program in a debugger, but many new programmers are not experienced with the debugger or are unwilling to use it, so this feature provides a middle ground.

This value is initially false but can be changed to true by calling this function and/or by defining the compiler flag SPL_CONSOLE_PRINT_EXCEPTIONS.

Usage:

setConsolePrintExceptions(exit);

Available since: 2014/02/01 version of C++ library


void setConsoleSize(double width, double height);
Changes the size of the console to the specified dimensions, measured in pixels.

Usage:

setConsoleSize(width, height);

void setConsoleWindowTitle(std::string title);
Changes the title bar text of the console window to the specified text.

Usage:

setConsoleWindowTitle(title);

Available since: 2014/11/13 version of C++ library