I'm trying to output directional arrows for a simple snake game in C++ on Windows 10. However, using this table as reference:
All I got is this tiny question mark in the console:
I would like to output the symbols 16, 17, 30 and 31. I'm not much of programmer so it could be some basic mistake, but some symbols do work while others result in that symbol above.
A small example:
void showSnake() {
char snakeHead;
snakeHead = 31;
cout << snakeHead; //THIS SHOWS THE TINY QUESTION MARK
snakeHead = 62;
cout << snakeHead; //THIS SHOWS THE ">" SYMBOL
}
You should use Unicode, you'll have much more choices for characters.
On https://en.wikipedia.org/wiki/List_of_Unicode_characters I found this symbol '▶' which looks similar to what you wanted to use.
Its unicode value is U+25BA
which means you can create a character with a value of '\u25BA'
in C++.
In practice however that value would go outside the range of the char
type so you have to use wide characters (wchar
) to get the job done.
As per this answer you should also toggle support for Unicode character in stdout using the _setmode
function (see here) from the C run-time library.
#include <iostream>
#include <io.h>
#include <fcntl.h>
int main() {
_setmode(_fileno(stdout), _O_U16TEXT);
std::wcout << L'\u25BA';
}