How can i read cyrillic text from VS2019 console

53 Views Asked by At
int main() {
    char faculty[20];
    ss=setlocale(LC_ALL, "");
    f = fopen("input.txt", "r");
    printf("Введите название факультета \n");
    scanf("%s", faculty);
    fgets(faculty, 19, f);  
    ....................... 

I can not read cyrillic text from console. I tried to change font, setlocale parameter, but nothing help. scanf function returns (it seems so) utf-16. Output to console is all right. Default code page in console - 866 and i don't know how to change it;

1

There are 1 best solutions below

1
Ulyouth On

Input code page is probably wrong. I suppose you are running your code in Windows, so you can change it with SetConsoleCP. Try it with code page 1251 (ANSI Cyrillic; Cyrillic (Windows)). It should look more or less like the following code:

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <Windows.h>

int main()
{
    wchar_t faculty[1024] = L"";

    setlocale(LC_ALL, "Russian");
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);

    wprintf(L"Введите название факультета \n");
    wscanf(L"%s", faculty);
    wprintf(L"%s\n", faculty);
}