Making Console Applications Somewhat Pretty

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.

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

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

Tags