Making Console Applications Somewhat Pretty

Tags
C++ Console

Console programs can be ugly. Fortunately, there is some built in characters that can produce table borders that can help liven things up a bit. (just a little)

When writing a console program in C++ one is limited to the characters that are available in the console. Attempting to go to the Windows Character Map will show really nice "Box Drawing Characters" trying to implement those characters is another story. Trying to implement a different character set other than the one that you are already working in can be a HUGE pain. It is better instead to work with what you have than what you don't have. Enter the C++ console character map:

#include <stdlib.h>
int main()
{
	for (int n = 0; n < 256; ++n)
	{
		char ch = (n<31) ? ' ' : n; // set non-printable to space
		cout << setw(6) << n << setw(3) << ch;
		if ((n + 1) % 8 == 0)
			cout << '\n';
	}
	return 0;
}

SOURCE: CPlusPlus.com

This will produce a grid of all of the characters available to you.

Including special characters is not as simple as simply copying and pasting it into your cpp file. You actually need to call the character by its hexadecimal value. For example, if you wish to produce a vertical bar which is character number 179 you need to run it through a decimal to hexadecimal converter to get its code to include it which is B3. Next tack on a backslash and a lowercase x at the beginning and you have your special character.

cout << "\xB3"

If calculating the hex values on your own doesn't seem like an effective use of your time. Here is a table for the single line border characters.

CharacterDecimal NumberHexadecimal Number
218DA
196C4
194C2
191BF
179B3
195C3
197C5
180B4
192C0
193C1
217D9
176B0
177B1
178B2
219DB
223DF
220DC

Clear!

Another useful thing for making consoles more appealing is to remove any text that is no longer relevant.

#include <stdlib.h>
int main(int argc, char* argv[])
{
  system("cls");
  return 0;
}

SOURCE: Stack Overflow