line-drawing box-drawing in console
I found this code in the archives (credit: andywestken):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
// Hello World! in a Box (for Windows console)
#include <iostream>
#include <string>
using namespace std;
int main ()
{
// Box edges and corners (all double thick line)
// T for top, B for bottom, L for left, R for right
const char TB = '\xCD'; // 205
const char LR = '\xBA'; // 186
const char TL = '\xC9'; // 201
const char TR = '\xBB'; // 187
const char BL = '\xC8'; // 200
const char BR = '\xBC'; // 188
string hello = "Hello World!";
string margin = " ";
string line(hello.length() + 2 * margin.length(), TB);
cout << TL << line << TR << endl;
cout << LR << margin << hello << margin << LR << endl;
cout << BL << line << BR << endl;
cout << endl;
return 0;
}
|
I want this for single, rather than doubled lines, but cannot find where the "magic numbers" come from. I would appreciate any assistance.
See Code page 437 (IBM PC)
http://www.ascii-codes.com/
Another way to approach this, display the characters in use on your system.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include <iomanip>
using namespace std;
// Display Character Set
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';
}
}
|
Topic archived. No new replies allowed.