_
_
____ ____2019-12-01 23:25:10
ASCII
____ ____, 2019-12-01 23:25:10

How to work with Russian characters in C++?

I am programming in Ubuntu and I ran into a problem: Russian characters are not displayed in the terminal.
Looked at the ASCII table and tried to deduce the character codes. Gives the wrong range and wrong characters.
How to solve this problem ?

#include <iostream>
#include <clocale>
using std::cout;
using std::endl;

int main(){
    setlocale(LC_CTYPE,"rus");
   unsigned char a = 'а';
   for(int i = 0; i < 34; i++){
   cout<<a<<" "<<static_cast<unsigned int>(a+i)<<endl;
   }
    return 0;
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2019-12-01
@BohTs

#include<iostream>
int main()
{
  std::cout << "пиши как есть" << std::endl;
}

look at the output in the terminal$ locale

R
Ronald McDonald, 2019-12-01
@Zoominger

#include <iostream>
#include <clocale>
 
using namespace std;
 
int main()
{
  setlocale(LC_ALL,"Russian");
  cout << "Привет, Мир!";
  return 0;
}

Check.

R
res2001, 2019-12-02
@res2001

Save the sources in UTF8 and rebuild. In Lina, UTF8 is now everywhere by default.
In older versions of Linux, the Russian locale was encoded as KOI8-R.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question