Trying to print unicode characters C++ assert failed

  ascii-art, c++, unicode

I’ve been trying to print Unicode characters. I’m new to C++. I’m on Windows 10 and using Visual Studio 2019.

I’m trying to print the following art in a console application:

██╗███╗░░██╗░██████╗░█████╗░███╗░░██╗██╗████████╗██╗░░░██╗
██║████╗░██║██╔════╝██╔══██╗████╗░██║██║╚══██╔══╝╚██╗░██╔╝
██║██╔██╗██║╚█████╗░███████║██╔██╗██║██║░░░██║░░░░╚████╔╝░
██║██║╚████║░╚═══██╗██╔══██║██║╚████║██║░░░██║░░░░░╚██╔╝░░
██║██║░╚███║██████╔╝██║░░██║██║░╚███║██║░░░██║░░░░░░██║░░░
╚═╝╚═╝░░╚══╝╚═════╝░╚═╝░░╚═╝╚═╝░░╚══╝╚═╝░░░╚═╝░░░░░░╚═╝░░░

I used _setmode(_fileno(stdout), _O_U16TEXT); which let me print it, but when trying to print some text, I get an assertion failed.

My code is this:

#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <Windows.h>

void banner() {

    _setmode(_fileno(stdout), _O_U16TEXT);
    wprintf(L"      ██╗███╗░░██╗░██████╗░█████╗░███╗░░██╗██╗████████╗██╗░░░██╗n");
    wprintf(L"      ██║████╗░██║██╔════╝██╔══██╗████╗░██║██║╚══██╔══╝╚██╗░██╔╝n");
    wprintf(L"      ██║██╔██╗██║╚█████╗░███████║██╔██╗██║██║░░░██║░░░░╚████╔╝░n");
    wprintf(L"      ██║██║╚████║░╚═══██╗██╔══██║██║╚████║██║░░░██║░░░░░╚██╔╝░░n");
    wprintf(L"      ██║██║░╚███║██████╔╝██║░░██║██║░╚███║██║░░░██║░░░░░░██║░░░n");
    wprintf(L"      ╚═╝╚═╝░░╚══╝╚═════╝░╚═╝░░╚═╝╚═╝░░╚══╝╚═╝░░░╚═╝░░░░░░╚═╝░░░n");
}
void login(std::string username, std::string password) {

}
void menu() {
    printf("Thank you For choosing Insanity");
}
int main()
{
    bool loggedin = false;
    if (loggedin) {
        banner();
        menu();

    }
    else {
        banner();
        printf("Please Login...n");
        printf("Username :");
    }
    return 0;
}

What am I missing here?

Source: Windows Questions C++

LEAVE A COMMENT