Unicode File Functions Using C ++

I am trying to read a text file in Unicode and write data to a text file. Here is the code. Reading works great. I can tell because it shows a false character on the console, but the output text file is empty. Any help would be appreciated!

int main() { wchar_t *filename=L"normal.txt"; FILE *infile; infile=_wfopen(filename,L"r"); wchar_t b[2]; fwscanf(infile,L"%ls",b); wprintf(L"The string read was :%ls\n",b);//Read a character from the file FILE *outfile; wchar_t *filetwo = L"one.txt"; outfile=_wfopen(filetwo,L"w, ccs=UTF-16LE"); fwprintf(outfile,L"%ls",b); fclose(outfile); getch(); return 0; } 

In addition, I need to deal with Devanagari scripts in particular. How many bytes do they take? If it's 4, you'll learn how to handle those using wchar_t because it has a width of only 2 bytes.

+4
source share
3 answers

Devanagari code points are all in BMP (you have the main block in U + 0900 and some additional ones in U + A8F0), so if text files are encoded as UTF-16, all characters occupy only one 16-bit word. (Do not think that this will always be the case.)

+3
source

Answering only the second question:

The characters of the Devanagari script are in the Basic Multilingual Plan . They are all 16-bit, so you are safe. Otherwise, you will have to face surrogate pairs .

+1
source

Found a solution !! I just needed to open the file in binary mode. Some characters are apparently ignored otherwise. Thanks for the ton for helping all the guys!

+1
source

Source: https://habr.com/ru/post/1446502/


All Articles