S
S
sudo rm -rf /2021-06-06 13:28:08
C++ / C#
sudo rm -rf /, 2021-06-06 13:28:08

Cross-platform solution for Cyrillic output. How to implement?

There is a project which I want to collect under Windows and Linux. I'm on macOS myself.
If under mac everything is assembled and displayed correctly in Russian, then there are some problems with windows.

I decided to use clocale and it didn't help either, P and ? are displayed in Windows.std::setlocale(LC_ALL, "Russian")

#include<iostream>
#include "approx_lib.h"

int main() {
    double circumference_number;

    std::cout << "Введите обхват (мм): ";


The forums suggest using solutions specific to windows (by connecting Windows.h or using special types for Windows), but these options are not suitable, as they will make building for other systems impossible.

What are the viable solutions?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir Korotenko, 2021-06-06
@firedragon

Standard solutions are something like
#if def("Win32")

R
res2001, 2021-06-06
@res2001

For Windows, you will have to make a separate implementation, because.
1. There are several Russian encodings in the Windows console (cp1251 and cp866, with cp866 by default).
2. In the Windows console, the encoding can be changed with the chcp command from the console itself on the fly.
So a normal implementation should know the current encoding and re-encode all output text into it. The same is true for console input.
Changing the encoding from the program is a bad option, although it works quite well.

A
Adamos, 2021-06-06
@Adamos

There are, in fact, two solutions - either bother with recoding yourself, sticking ifdefs into the code, or use a cross-platform library where someone did it for you.

M
Murad Murtuzaliev, 2021-06-06
@ordinary_programmer

https://www.cplusplus.com/reference/string/wstring/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question