Home > Software engineering >  Use a Unicode character in a char variable (C )
Use a Unicode character in a char variable (C )

Time:12-04

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?

CodePudding user response:

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'█'.

  • Related