I wrote a translator from decimal number to Unicode characters.
In the input file, we have several numbers that after the translation will give out some character. For example, the euro sign, represented as 226 130 172 at the outset, will look exactly like a euro sign. The problem is that I can not output this to a file, but I can output it to the console. In the program there is a method with extended fstream, it allows to output symbols up to 4 bytes to the console. But there is nothing in the output file, and I do not understand why.My friend uses some way to output, redirecting the normal cout stream to a file, but, as I understand, this method will only work on Windows. I use Ubuntu 16.04, this method does not work for me. I tried to configure the gedit (standard text editor in Ubuntu) to display, but I did not succeed. In this code, I first open the extended streams, and then the following code goes.
int input, result = 0;
if(!fin.is_open()){
cout << "Не удалось открыть файл!" << endl;
}
else{
while(fin >> input){
if(input >= 240){
input -= 240;
result += input << 18;
fin >> input;
input -= 128;
result += input << 12;
fin >> input;
input -= 128;
result += input << 6;
fin >> input;
input -= 128;
result += input;
wcout << (wchar_t)result << endl;
fout << (wchar_t)result;
}
else if(input >= 224){
input -= 224;
result += input << 12;
fin >> input;
input -= 128;
result += input << 6;
fin >> input;
input -= 128;
result += input;
wcout << (wchar_t)result << endl;
fout << (wchar_t)result;
}
else if(input >= 192){
input -= 192;
result += input << 6;
fin >> input;
input -= 128;
result = input;
wcout << (wchar_t)result << endl;
fout << (wchar_t)result;
}
else{
wcout << (wchar_t)input << endl;
fout << (wchar_t)input;
}
}
}
fin.close();
fout.close();
return 0;
}