+ 3

Can you enable UTF-16 encoding (emojis) with the c++ preprocessor?

It does change the error stream, but how? I honestly don't know if this is a dead end or a possible 1-liner. Does anyone have any ideas? https://code.sololearn.com/cHhj9vqH9qAp/?ref=app

5th Oct 2018, 5:30 AM
Kirk Schafer
Kirk Schafer - avatar
3 Respostas
+ 10
Kirk Schafer Yeah I checked it out too. It's strange that the other wide commands are not working. Also I noticed another thing, if we try to print normal text/string it prints some sort of Chinese words and also none of the escape sequences work. #include <iostream> int main() { wprintf(L"%s", L"\xfeff☺😄"); wprintf(L"%s", L"👍"); printf("%s", L"👌"); printf("%s", L"🌩️"); std::wcout << L"☂️"; printf("Hello\n"); return 0; } Above code works fine with no errors, but you must see the output of the last print command. If there's a way to remove BOM, then maybe the last command works fine.
6th Oct 2018, 9:52 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 9
I am not better than you but I tried changing to your code and it worked fine. #include <iostream> int main() { wprintf(L"%s", L"\xfeff☺😄"); wprintf(L"%s", L"👍"); printf("%s", L"👌"); return 0; } It seems that BOM is required at least once to know the compiler that in what way should the encoding/decoding be done.
5th Oct 2018, 7:28 AM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
nAutAxH AhmAd Well, my earlier answer dropped; sorry for the delay in recreating my response. Your answer indeed works, which is both neat and perplexing -- it doesn't require resetting stdout (could be the Long specifiers?) but the other wide-output commands (when used after this new approach) don't seem to work in the model used in both of our CodePlayground codes. This is mysterious to me, because once you set the BOM, I feel like it should just keep working...
6th Oct 2018, 1:54 AM
Kirk Schafer
Kirk Schafer - avatar