divinelemon
divinelemon

Reputation: 2097

Use a Unicode character in a char variable (C++)

I get some input from the command line and want to support Unicode.

This is my error:

Repl.it output error

And this is my example code:


#include <iostream>

int main() {
  char test = '█';
} 

// Characters wanted: █, ▓, or ▒

How can I make my program support Unicode?

Upvotes: 1

Views: 445

Answers (1)

Salvage
Salvage

Reputation: 509

A char is usually only 1 byte, meaning it won't be able to store most Unicode characters. You should look into using wchar_t which is required to be large enough to hold any supported character codepoint. The associated char literal looks as follows: L'█'.

Upvotes: 4

Related Questions