char arr [] = {'a', 'b', 'c', 'g'} when I write such an array it gives an error "error: excess elements in char array initializer" what should I do to fix it? I did not write a console application in Qt (if necessary)

  • four
    What encoding do you want to store Cyrillic in? If UTF-8, then Cyrillic takes two bytes, and you need to store each letter in std::string or something like that. - HolyBlackCat
  • four
    Why the Qt tag? If you use Qt, then it is unnecessary to use char , in Qt there are enough tools to work with Unicode. - ixSci
  • one
    Also make sure that the source file is utf-8 , if the Cyrillic alphabet is in the code itself - gil9red
  • What kind of compiler, IDE, OS? in VS it compiles without problems - Pavel Gridin 8:01 pm

2 answers 2

Your source code has some kind of encoding, Cyrillic characters are written into the code in this encoding. Writing char arr [] = {'a', 'b', 'c', 'd'} means that you type the code in a single-byte encoding, and initialize the byte array with the codes of the Cyrillic letters in this particular encoding, while IDEs use unicode by default (for example, utf-8), hence the compilation error. If you really need an array of characters in unicode, then on Qt you can initialize it like this: QChar arr[] = {u'а', u'б', u'в', u'г'}

    The char type does not support unicode. Therefore, use the wchar_t type.