K
K
KPIshnik2014-01-28 18:55:23
C++ / C#
KPIshnik, 2014-01-28 18:55:23

How to write Cyrillic and symbols of other languages ​​to a text file?

Hello. There was a problem: you need to write the file names (I have an array of wchar_t ** filenames) into a text file. With English names, everything is fine, the problem is with all other alphabets. Prompt a method how to implement record for all languages.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
KPIshnik, 2014-01-28
@KPIshnik

who is interested, solved the problem with this function

WideCharToMultiByte(CP_ACP,WC_COMPOSITECHECK,wfilename[0],-1,chName1,sizeof(chName1),NULL,NULL)

F
Fat Lorrie, 2014-01-28
@Free_ze

So this is... std::wofstream.

L
Lolshto, 2014-01-28
@Lol4t0

In fact, it is correct to write all the same through streams, you only need to set the locale settings as expected.
With Visual Sudio, everything is simple:

std::locale::global(std::locale("Russian"));
std::wcout << L"привет";

Mingw does not know how to use Windows locales, so you need to write a bicycle (except that CP_ACPinstead ofCP_OEM

A
AxisPod, 2014-01-29
@AxisPod

Deal with encodings first, Windows loves UTF-16 (actually UCS-2), while posix systems are UTF-8. UTF-8 is essentially stored in a regular char, it is a multi byte encoding, the character size is floating from 1 to 4 bytes, it is more difficult to work with these strings. UTF-16 is always a 2-byte character set, stored in wchar_t. As a result, with UTF-8, all the same writing methods are used as for regular ANSI (std:: ofstream), in general, if character-by-character work is not required, then all ANSI methods are suitable. Whereas UTF-16 uses its own methods, objects (std::wofstream). Well, their heirs. In parentheses, I indicated the streams that can be saved.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question