Insert character by character of the Russian alphabet into a char vector in C++

Asked

Viewed 148 times

1

Hello I would like to know how to insert characters (of the manual form) of the Russian alphabet in a char vector, because I am trying the form below and the problems in the press. Follows the code:

#include <iostream>

int main(){

    char coisa[6];

    coisa[0]='з';
    coisa[1]='е';
    coisa[2]='м';
    coisa[3]='л';
    coisa[4]='я';

    std::cout << coisa << "\n";

}
  • Try: setlocale(LC_ALL, "Russian");

  • I’ve tried...continues the same thing. Follow the code: #include <iostream> #include <locale. h> int main(){ setlocale(LC_ALL, "Russian"); char thing[6]; thing[0]='з'; thing[1]='е';'; thing[2]=';}

1 answer

3


The call of setlocale( LC_ALL, "" ); (with the second blank parameter), causes the default locale of the program to be set according to the variables of its environment.

If you are working with the Cirilico alphabet, surely the environment where you are running your program uses coding UTF-8.

Follow your modified example:

#include <iostream>
#include <locale>

int main(){

    setlocale( LC_ALL, "" );

    wchar_t coisa[6];

    coisa[0] = L'з';
    coisa[1] = L'е';
    coisa[2] = L'м';
    coisa[3] = L'л';
    coisa[4] = L'я';
    coisa[5] = L'\0';

    std::wcout << coisa << std::endl;
}

The coding UTF-8 covers virtually all existing alphabets, making the language an expendable detail:

#include <iostream>
#include <locale>


int main(){

    setlocale( LC_ALL, "" );

    std::wstring ch = L"你好世界";
    std::wstring gk = L"γειά σου κόσμος";
    std::wstring jp = L"こんにちは世界";
    std::wstring ko = L"여보세요 세계";
    std::wstring pt = L"Olá mundo!";
    std::wstring ru = L"Здравствулте мир!";

    std::wcout << L"Chinês    : " << ch << std::endl;
    std::wcout << L"Grego     : " << gk << std::endl;
    std::wcout << L"Japonês   : " << jp << std::endl;
    std::wcout << L"Coreano   : " << ko << std::endl;
    std::wcout << L"Português : " << pt << std::endl;
    std::wcout << L"Russo     : " << ru << std::endl;

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.