I am trying to help a friend with a project that was supposed to be 1st, and now has been 3 days. Needless to say, I feel very upset and angry ;-) ooooouuuu ... I'm breathing.
Thus, a program written in C ++ simply reads a bunch of files and processes them. The problem is that my program reads files that use UTF-16 encoding (because the files contain words written in different languages), and the simple use of ifstream just doesn't work (it reads and displays garbage). It took me a while to realize that this was due to the fact that the files were in UTF-16.
Now I spent literally all day on the Internet trying to find information on READING UTF16 files and converting the contents of the UTF16 line to char! I just can't seem! A nightmare. I am trying to learn about <locale> and <codecvt> , wstring, etc., which I have never used before (I specialize in graphical applications, not desktop applications). I just can't get it.
This is what I did with the tariff (but does not work):
std::wifstream file2(fileFullPath); std::locale loc (std::locale(), new std::codecvt_utf16<char32_t>); std::cout.imbue(loc); while (!file2.eof()) { std::wstring line; std::getline(file2, line); std::wcout << line << std::endl; }
This is the maximum that I could come up with, but it does not even work. And it does nothing better. But the problem is that I donโt understand what I am doing in the first place.
WITH PLEASE PLEASE HELP! It really goes crazy that I can even read the text file G *** D ***.
Upstairs, my friend uses Ubuntu (I use clang ++), and this code requires -stdlib = libC ++, which does not seem to be supported by gcc on its side (although it uses a rather advanced version of gcc, which 4.6.3 I consider). Therefore, Iโm not even sure that using codecvt and locale is a good idea (as in โmaybeโ). There would be a better (different) option.
If I convert all files to utf-8 only from the command line (using the linux command), am I going to potentially lose information?
Thank you very much, I will be grateful if you help me with this.