I use CLion, MinGW.
When I want to write Cyrillic characters to a file, are written to the file \0
, but in the console everything is fine.
If I use windows-1251 encoding then everything is fine, but if I do cout << "Привет", in console will Привет
#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
int main() {
system("CHCP 65001 > nul");
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
fstream fileStream;
fileStream.open("file.txt", ios_base::in | ios_base::out | ios_base::app);
string message;
cin >> message;
fileStream << message << endl;
fileStream.close();
}