Displaying Japanese text in C++

I'm unsure if this is a c++ issue or a Compiler issue, but i believe you should be able to display foreign characters in C++ so I assume its a C++ thing. So I want to display this text in my program: きゃっかんてき and I did this:

1
2
3
4
5
6
7
8
9
10
11
  #include <iostream>

using namespace std;

int main()
{
    cout << "きゃっかんてき" << endl;
    cout << L"きゃっかんてき" << endl;
    return 0;
}


the first output gives me strange characters and the second gives me a memory address (0x47403c) so how do I display this text in c++? I thought L in front of the string was used to display exotic characters? My Compiler is CodeBlocks btw,.
Last edited on
Alas, you've got to set up the console properly, and using the standard C++ streams is unlikely to work unless you are encoding with UTF-8.
http://www.cplusplus.com/forum/general/81427/
Hope this helps.
On Linux cout << "きゃっかんてき" << endl; usually works fine without doing anything special because the default encoding used is UTF-8.
Hmm, I cant seem to figure it out, i'm on windows 8 as well, don't use linux :(
At the command prompt, type

chcp 65001

Next, compile and run:

1
2
3
4
5
6
7
#include <iostream>
using namespace std;

int main()
{
  cout << u8"きゃっかんてき" << "\n";
}

Does that not work?
no still doesnt work
At all? You aren't getting output? Your output is garbled?

What version of GCC are you using?

Does the following program work? (Remembering to chcp 65001 first)?

1
2
3
4
5
6
7
#include <iostream>
using namespace std;

int main()
{
  cout << "\n" "\xE3\x81\x8D" "\xE3\x82\x83" "\xE3\x81\xA3" "\xE3\x81\x8B" "\xE3\x82\x93" "\xE3\x81\xA6" "\xE3\x81\x8D" "\n";
}

(That's the hiragana explicitly in UTF-8.)

This test tells me whether or not the issue is with either your editor or libc++ vs the console setup. :OJ

(Also, I forgot that the Console has something of a bug in it. You must output something 7-bit before anything UTF-8 in order for it to not garble き. Hence the newline at the front. Soulless console.)
no that doesnt work either. I open cmd then type that in then compile my progrtam right? if so, then thats what i did and it doesnt work :(
Open console, change codepage, then launch already compiled program from that console. Note that font used by console usually does not support anything non-ASCII, so you will have to make sure that current console font is able to display those characters
Ah, yes, that's an important point. In the top left corner of your Console Window, right-click the icon and select "Properties" from the popup-menu. Select the "Font" tab in the window that appears and make sure "Lucida Console" is the chosen font. Click "OK' to save your changes. If it asks, you might as well make the changes permanent for all future invocations of the Windows Console as well.
I use Code::blocks too, it has to do with the encoding. If you encode it in UTF-8 It does not work. Noe: I did not read any posts before this
Last edited on
Topic archived. No new replies allowed.