console.h
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 | |
Erases the contents of the console window. | |
Returns whether console output is also sent to the plain text console. | |
Returns whether console should shut down the entire program when it is closed. | |
Returns whether console should catch and display exceptions that occur when the program is running. | |
Changes whether console output is also sent to the plain text console. | |
Changes whether console should shut down the entire program when it is closed. | |
Changes the font used for the console. | |
Changes the x/y position of the console on screen. | |
Changes whether console should catch and display exceptions that occur when the program is running. | |
Changes the size of the console to the specified dimensions, measured in pixels. | |
Changes the title bar text of the console window to the specified text. |
void clearConsole();
Usage:
clearConsole();
bool getConsoleEcho();
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();
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();
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);
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);
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);
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);
Usage:
setConsoleLocation(x, y);
Available since: 2014/02/01 version of C++ library
void setConsolePrintExceptions(bool print);
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);
Usage:
setConsoleSize(width, height);
void setConsoleWindowTitle(std::string title);
Usage:
setConsoleWindowTitle(title);
Available since: 2014/11/13 version of C++ library