I assume this doesn't work because cout is an ostream object, and i need to write to a wostream object. So, whats the wostream object? i tried wcout, and it didn't work, not surprisingly
wcout doesn't properly write wide characters to the output device -- it calls narrow() on each wchar_t to convert it to a char, then outputs it just like cout does...
I'd say the sanest thing to do is convert the string to UTF-8 (or some other multi-byte encoding) and write that to std::cout. The standard streams aren't very good for wide characters.
Dev-C++'s MinGW is outdated and cripplingly non-conforming.
well, the whole point was to output spanish letters, which dont have ASCII codes so I need UTF-16 at least. and the ultimate goal is to write them to a window with drawtext() or something similar. Is there a function similar to drawtext that handles wide characters?
yeah, i heard Dev C++ was pretty bad, but it was free, so yeah.
can i just use the latest MinGW with Dev C++? I'll have to look into that
Do you need to do this portably? If you do, this is a lost battle. If you don't, there are ways to do it. For example, you could assume a given code page is being used (I can't remember at the moment what the Windows equivalent of ISO 8859-1 is) and output single byte characters.
#include <iomanip>
#include <iostream>
usingnamespace std;
int main()
{
int c, n;
cout << setw( 5 ) << "+";
for (n = 0; n < 16; n++)
cout << setw( 3 ) << n;
cout << endl;
for (n = 32, c = 32; c < 254; c++)
{
if ((n % 16) == 0)
cout << setw( 5 ) << n;
cout << setw( 3 ) << (char)c;
if ((++n % 16) == 0)
cout << endl;
}
cout << endl;
return 0;
}
The characters 129 and 160-168 and 173-175 are all used in Spanish. You just need to convert your Unicode strings to the default MS console codepage (8-bit characters) before outputting your strings.
You should be able to do this with a simple function that returns a modified string, which you can then pass to [w]cout.
Yeah, my goal isn't to write to the console, I'm trying to use DrawText() to draw to a window. I have the window part working fine, i just wanted to draw Spanish characters. If the Spanish characters have ASCII codes, can I just avoid wstrings altogether?
The Spanish characters do not have ASCII codes. They are in the default code page Microsoft uses with the console.
However, since you aren't interested in the console and are instead using DrawText(), you shouldn't have any problem. What is it that isn't working for you?
(Did you make sure to select a Unicode font to draw with?)