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

How to fix UTF-8 with cyrillic problem in my code?

#include <iostream>
#include <windows.h>
#include <locale.h>
#include <locale>

using namespace std;

int main()
{
    setlocale(LC_ALL, ".UTF-8");
    locale global(locale(".UTF-8"));

    const float Pi = 3.14;

    float r, h;
    
    cout << "Введіть довжину (r): ";
    cin >> r;

    cout << "Введіть висоту (h): ";
    cin >> h;


    float d, s, v, sb;

    d = 2 * r;
    sb = 2 * Pi * r * h;
    s = 2 * Pi * r*(r + h);
    v = Pi * pow(r, 2) * h; 

    cout << "d = " << d << "\nSбіч = " << sb << "\nS= "<< s <<"\nV= " << v;

    return 0;

}

(English Win11)

I tried:

setlocale (LC_ALL, "ukr";

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

setlocale (LC_ALL, ".UTF-8");
locale global(locale(".UTF-8"));

and

Save documents as Unicode when data cannot be saved in codepage checkbox

and also

edit my region settings.

But nothing of this wont work

>Solution :

This works for me

#include <io.h>
#include <fcntl.h>
#include <iostream>

int main() {
    _setmode(_fileno(stdout), _O_U16TEXT);
    std::wcout << L"Введіть довжину (r):\n";
    return 0;
}

It’s the simple way to print Unicode characters on Windows. Put the stream into _O_U16TEXT mode and use wide strings L"..." and wide streams std::wcout.

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