How to solve the problem of accentuation in the terminal?

Asked

Viewed 860 times

1

I’m writing some strings on screen using the Opengl library and some of the words saved are accentuated words, example: república checa, where the exit ends up being: repblica checa has how to solve this problem without using external library? I would not like to use the #include <locale> for fear of incompatibility between windows or linux systems, some solution?

One remark, using the ASCII table is not a viable option.

1 answer

3


Maybe std::wcout (wchar_t) solve your problem

#include <iostream>

int main() {
    std::wcout << L"república" << std::endl;
    return 0;
}

In windows to work like this reply on Soen it is necessary to start by cmd with the /u

Another thing you can try in the case of Windows is to use _setmode as described here: https://msdn.microsoft.com/pt-br/library/tw4k6df8.aspx (this worked without needing to apply the /u)

#include <fcntl.h>
#include <io.h>
#include <stdio.h>

int main(void) {
    _setmode(_fileno(stdout), _O_U16TEXT);
    wprintf(L"república\n");
    return 0;
}

Upshot:

Resultado da aplicação C++ com Unicode

I tested it on Visualstudio and Mingw

Browser other questions tagged

You are not signed in. Login or sign up in order to post.