How do I make this shape in C++?

This is the shape that I am trying to make. Apparently, this was made by using box drawing characters. I tried using them in C++ but all I got is "?" instead of the drawing characters when I ran the program.
How do I fix this? (For what I know, these are uni codes and I can't use them in C++ or is it wrong?)
Can someone provide a small code which could provide an idea what can I do to make this shape? Thank you!


1
2
3
4
5
6
7
┌───┬───┬───┬───┬───┬───┐
│   │   │   │   │   │   │ 
├───┼───┼───┼───┼───┼───┤
│   │   │   │   │   │   │ 
├───┼───┼───┼───┼───┼───┤
│   │   │   │   │   │   │ 
└───┴───┴───┴───┴───┴───┘



For now, this is how my code looks like.

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
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std; 
int main()
{
	int COLS = 3; 
	int ROWS = 6; 
	char shape1[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };
	char shape2[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };
	for (int col = 0; col < ROWS; ++col)
		cout << "----";
	cout << "-";
	for (int space = 1; space <= 13; space++)
		cout << " ";
	for (int col = 0; col < ROWS; ++col)
		cout << "----";
	cout << "-\n";

	for (int row = 0; row < COLS; ++row)
	{
		cout << "| ";
		for (int col = 0; col < ROWS; ++col)
			cout << shape1[row][col] << " | ";
		for (int space = 1; space <= 12; space++)
			cout << " ";
		cout << "| ";
		for (int col = 0; col < ROWS; ++col)
			cout << shape2[row][col] << " | ";
		cout << '\n';
		for (int col = 0; col < ROWS; ++col)
			cout << "----";
		for (int space = 1; space <= 14; space++)
			cout << " ";
		for (int col = 0; col < ROWS; ++col)
			cout << "----";
		cout << "-\n";
	}
	system("pause");
}


Following is the output of this code.

1
2
3
4
5
6
7
8
|   |   |   |   |   |   |             |   |   |   |   |   |   |
------------------------              -------------------------
|   |   |   |   |   |   |             |   |   |   |   |   |   |
------------------------              -------------------------
|   |   |   |   |   |   |             |   |   |   |   |   |   |
------------------------              -------------------------
Press any key to continue . . .


Since, the above one isn't very good looking, I tried using box drawing characters as shown in the following code (please note this isn't the complete code I made.. I lost that code which I made so I have just made 2-3 alterations to the above code, to show the problem I am getting)


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
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std; 
int main()
{
	int COLS = 3; 
	int ROWS = 6; 
	char shape1[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };
	char shape2[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };
	for (int col = 0; col < ROWS; ++col)
		cout << "━━";
	cout << "-";
	for (int space = 1; space <= 13; space++)
		cout << " ";
	for (int col = 0; col < ROWS; ++col)
		cout << "━━";
	cout << "-\n";

	for (int row = 0; row < COLS; ++row)
	{
		cout << "┃ ";
		for (int col = 0; col < ROWS; ++col)
			cout << shape1[row][col] << " ┃ ";
		for (int space = 1; space <= 12; space++)
			cout << " ";
		cout << "┃ ";
		for (int col = 0; col < ROWS; ++col)
			cout << shape2[row][col] << " ┃ ";
		cout << '\n';
		for (int col = 0; col < ROWS; ++col)
			cout << "━━";
		for (int space = 1; space <= 14; space++)
			cout << " ";
		for (int col = 0; col < ROWS; ++col)
			cout << "━━";
		cout << "-\n";
	}
	system("pause");
}


Using this code, I am getting this kind of output.. All those characters are now replaced by "?" and I don't know how to resolve this issue.

1
2
3
4
5
6
7
8
9
10
????????????-             ????????????-
?   ?   ?   ?   ?   ?   ?             ?   ?   ?   ?   ?   ?   ?
????????????              ????????????-
?   ?   ?   ?   ?   ?   ?             ?   ?   ?   ?   ?   ?   ?
????????????              ????????????-
?   ?   ?   ?   ?   ?   ?             ?   ?   ?   ?   ?   ?   ?
????????????              ????????????-
Press any key to continue . . .




As for my OS, it is Windows 10 x64 and I am not sure about the compiler but I am using Visual Studio 2017
Last edited on
1. Post your actual code.
2. Say what OS/Compiler you're using.
For now, this is how my code looks like.

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
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std; 
int main()
{
	int COLS = 3; 
	int ROWS = 6; 
	char shape1[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };
	char shape2[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };
	for (int col = 0; col < ROWS; ++col)
		cout << "----";
	cout << "-";
	for (int space = 1; space <= 13; space++)
		cout << " ";
	for (int col = 0; col < ROWS; ++col)
		cout << "----";
	cout << "-\n";

	for (int row = 0; row < COLS; ++row)
	{
		cout << "| ";
		for (int col = 0; col < ROWS; ++col)
			cout << shape1[row][col] << " | ";
		for (int space = 1; space <= 12; space++)
			cout << " ";
		cout << "| ";
		for (int col = 0; col < ROWS; ++col)
			cout << shape2[row][col] << " | ";
		cout << '\n';
		for (int col = 0; col < ROWS; ++col)
			cout << "----";
		for (int space = 1; space <= 14; space++)
			cout << " ";
		for (int col = 0; col < ROWS; ++col)
			cout << "----";
		cout << "-\n";
	}
	system("pause");
}


Following is the output of this code.

1
2
3
4
5
6
7
8
|   |   |   |   |   |   |             |   |   |   |   |   |   |
------------------------              -------------------------
|   |   |   |   |   |   |             |   |   |   |   |   |   |
------------------------              -------------------------
|   |   |   |   |   |   |             |   |   |   |   |   |   |
------------------------              -------------------------
Press any key to continue . . .


Since, the above one isn't very good looking, I tried using box drawing characters as shown in the following code (please note this isn't the complete code I made.. I lost that code which I made so I have just made 2-3 alterations to the above code, to show the problem I am getting)


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
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std; 
int main()
{
	int COLS = 3; 
	int ROWS = 6; 
	char shape1[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };
	char shape2[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };
	for (int col = 0; col < ROWS; ++col)
		cout << "━━";
	cout << "-";
	for (int space = 1; space <= 13; space++)
		cout << " ";
	for (int col = 0; col < ROWS; ++col)
		cout << "━━";
	cout << "-\n";

	for (int row = 0; row < COLS; ++row)
	{
		cout << "┃ ";
		for (int col = 0; col < ROWS; ++col)
			cout << shape1[row][col] << " ┃ ";
		for (int space = 1; space <= 12; space++)
			cout << " ";
		cout << "┃ ";
		for (int col = 0; col < ROWS; ++col)
			cout << shape2[row][col] << " ┃ ";
		cout << '\n';
		for (int col = 0; col < ROWS; ++col)
			cout << "━━";
		for (int space = 1; space <= 14; space++)
			cout << " ";
		for (int col = 0; col < ROWS; ++col)
			cout << "━━";
		cout << "-\n";
	}
	system("pause");
}


Using this code, I am getting this kind of output.. All those characters are now replaced by "?" and I don't know how to resolve this issue.

1
2
3
4
5
6
7
8
9
10
????????????-             ????????????-
?   ?   ?   ?   ?   ?   ?             ?   ?   ?   ?   ?   ?   ?
????????????              ????????????-
?   ?   ?   ?   ?   ?   ?             ?   ?   ?   ?   ?   ?   ?
????????????              ????????????-
?   ?   ?   ?   ?   ?   ?             ?   ?   ?   ?   ?   ?   ?
????????????              ????????????-
Press any key to continue . . .




As for my OS, it is Windows 10 x64 and I am not sure about the compiler but I am using Visual Studio 2017
Hello redfury,

What I have found with VS2017 is that the IDE and the console window will display characters differently especially the ones above decimal 127.

For the character "┌" I type in alt+0218. The character in the IDE shows as "Ú", but prints in the console window as "┌". Kind of screwed up, but it works.

This prints one box, but you can build on it from there:
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>

//using namespace std;  // <--- Best not to use.

int main()
{
	constexpr size_t ROWS = 3;  // <--- Changed.
	constexpr size_t COLS = 6;  // <--- Changed.

	char shape1[ROWS][COLS]  // <--- Changed.
	{
		{'Ú', 'Ä', 'Ä', 'Ä', 'Ä', '¿'},
		{'³', ' ', ' ', ' ', ' ', '³'},
		{'À', 'Ä', 'Ä', 'Ä', 'Ä', 'Ù'}
	};
	char shape2[3][6] = { {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' ', ' ', ' '} };

	for (size_t row = 0; row < ROWS; row++)
	{
		for (size_t col = 0; col < COLS; col++)
		{	
			std::cout << shape1[row][col];
		}

		std::cout << std::endl;
	}

	//for (int col = 0; col < ROWS; ++col)
	//	cout << "━━";
	//cout << "-";
	//for (int space = 1; space <= 13; space++)
	//	cout << " ";
	//for (int col = 0; col < ROWS; ++col)
	//	cout << "━━";
	//cout << "-\n";

	//for (int row = 0; row < COLS; ++row)
	//{
	//	cout << "┃ ";
	//	for (int col = 0; col < ROWS; ++col)
	//		cout << shape1[row][col] << " ┃ ";
	//	for (int space = 1; space <= 12; space++)
	//		cout << " ";
	//	cout << "┃ ";
	//	for (int col = 0; col < ROWS; ++col)
	//		cout << shape2[row][col] << " ┃ ";
	//	cout << '\n';
	//	for (int col = 0; col < ROWS; ++col)
	//		cout << "━━";
	//	for (int space = 1; space <= 14; space++)
	//		cout << " ";
	//	for (int col = 0; col < ROWS; ++col)
	//		cout << "━━";
	//	cout << "-\n";
	//}

	//system("pause");  // <--- Best not to use.
		// <--- Used mostly for testing in Debug mode. Removed if compiled for release.
	// <--- Used to keep the console window open in Visual Studio Debug mode.
	// The next line may not be needid. If you have to press enter to see the prompt it is not needed.
	//std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires header file <limits>.
	std::cout << "\n\n Press Enter to continue: ";
	std::cin.get();

	return 0;

}

Hope that helps,

Andy
Topic archived. No new replies allowed.