imagine these line:
cout << "glória vitória"; //glory vitory
why instead print 'ó', prints '3/4'(the ascii char)???
changing the console font name, can resolve it?
imagine these line:
cout << "glória vitória"; //glory vitory
why instead print 'ó', prints '3/4'(the ascii char)???
changing the console font name, can resolve it?
The good news is you can do it. The bad news is you have little choice but to use a platform dependent method to set the console into a wide character mode. For example:
#include <iostream>
#include <fcntl.h>
#include <io.h>
using namespace std;
int main()
{
_setmode(_fileno(stdout), _O_U16TEXT);
wcout << L"glória vitória\n";
}
sorry i get these error:
"error: converting to execution character set: Illegal byte sequence"
That's an issue with your code editor. If you can set the character set to something like Unicode, you should be good to go.
i try with _T() and _TEXT(), but only show me the 1st letter :(
#include <clocale>
#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "");//these is the important line
cout << "úçéûi"; // yes the cout works too;)
return 0;
}
thanks too all
seems that the don't works for cin... why?
The istream
and ostream
classes work with char
s, rather than wchar_t
s, and won't interpret wide chars correctly. However, changing them to work with wchar_t
would break a large amount of existing code, so they have to be retained for backwards compatibility. Naturally, the standards commitee wanted to provide a portable solution to this, and to this end, the standard now defines wistream
and wostream
classes, and mirror objects for the standard input and output: wcin
and wcout
. To work with wide chars, you will want to use those instead of cin
and cout
.
after more search i found it ;)
here i use 'en_US.UTF-8' string option, but we can change it for other types
setlocale(LC_ALL, "en_US.UTF-8");
about it:
> The setlocale function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to setlocale. If locale is a null pointer, setlocale queries the current C locale without modifying it.
> Parameters
> category - locale category identifier, one of the LC_xxx macros. May be 0.
> locale - system-specific locale identifier. Can be "" for the user-preferred locale or "C" for the minimal locale
> Return value
>
> Pointer to a narrow null-terminated string identifying the C locale after applying the changes, if any, or null pointer on failure.
heres the page about it:
http://en.cppreference.com/w/cpp/locale/setlocale
thansk for all... thanks
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.