I'm working on a console game, which uses ASCII symbols as pixels. The map for this game is stored in a .txt file:
████████████████
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
█ █
████████████████
To display the map I'm reading it from a file demo.txt line by line and writing each character to CHAR_INFO *screen:
void setScreen(const char* layoutFile, const char* levelDataFile) {
std::ifstream levelData(levelDataFile);
levelData >> width >> height;
field = {0, 0, (SHORT)width, (SHORT)height};
screen = new CHAR_INFO[width * height];
levelData.close();
std::ifstream layout(layoutFile); //reading from a file `demo.txt`
std::string line;
for (int j = 0; j < height; j++) {
getline(layout, line);
for(int i = 0; i < width; i++) {
screen[j * width + i].Char.AsciiChar = line[i]; //writing each character of a line to screen
screen[j * width + i].Attributes = BACKGROUND_GREEN;
}
}
layout.close();
}
After that I'm displaying a map using the following function (map.getScreen() returns pointer to screen array):
WriteConsoleOutputA(
console.getHOut(),
map.getScreen(),
{ (SHORT)map.getWidth(), (SHORT)map.getHeight() },
{ 0,0 },
&map.getField()
);
But the problem is that █ are displayed as �, and the output looks like this:
����������������
���
���
���
���
���
���
���
���
���
���
���
���
���
���
����������������
Some things i tried:
SetConsoleOutputCP(CP_UTF8); SetConsoleCP(CP_UTF8);SetConsoleCutputCP(1251);setlocale(LC_ALL, "");std::locale::global(std::locale(std::locale::empty(), new std::codecvt_utf8<wchar_t>));