Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And this is my example code:


#include <iostream>

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

// Characters wanted: █, ▓, or ▒

How can I make my program support Unicode?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading