K
K
kos_dev2021-10-15 00:01:48
C++ / C#
kos_dev, 2021-10-15 00:01:48

How to write Cyrillic alphabet to file via fstream?

VS 2019, C++ 20.
I tried a lot of options, I just can't write char / string with Cyrillic to a file.
I get something similar from broken bytes ( Encoding in UTF-8 text editor)
Each character is 2 bytes, broken characters are dw0, dw1

UTF-8 in a text editor
�w�w�w�w�wy1diq�w�wy�w�w�w�w�w�w�w�w


If I put CP1251 in a text editor, it shows this:

CP1251 in text editor
РwРwРwРwСwy1diqРwСwyРwРwРwРwСwРwСwСw,yСw


I tried to put the locale in the write / read stream
locale
locale loc("ru-RU"); fout.imbue(loc);


One attempt to output to a file:
outstream
vector<char> decode = efi.decrypt(enc);

fout.open("3.txt");
for (int i = 0; i < decode.size(); i++)
    fout << decode[i];
fout.close();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anikavoi, 2021-10-15
@kos_dev

https://www.codeproject.com/Articles/38242/Reading...
https://stackoverflow.com/questions/5026555/c-how-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question