2

Hello guys I'm making a little Text Based Adventure Game for school and I was wondering if you can add Unicode to C++. Right now I added this: Д but when I debugged my game it was just a "?" instead of "Д". I am using the iostream "cout" method of outputting text. Do I need to include something? I use Visual Studio Express 2012.

This is how I typed Д:

cout << "Д  |" << endl; //It's a part of the map
celtschk
  • 19,311
  • 3
  • 39
  • 64
Carlos Lombardii
  • 243
  • 3
  • 5
  • 11

2 Answers2

7

Under Visual Studio, you can choose between several options Multi-Bytes, Unicode, and a third.

You will find that property in the project properties box,
right click on your project in the "Solution Explorer", select "Properties" (at the bottom), in the option tree go to "general", you will something like:

enter image description here

Select Unicode, Apply and Close.
Now rebuild the project, and it will work.

alexbuisson
  • 7,699
  • 3
  • 31
  • 44
0

For your particular example, this works for me, albeit I have this in my vim: "fileencoding=utf-8". That might have an impact. As for VS2012, I expect to do something similar like here, but instead of "off", you need to put "on": How do I turn off Unicode in a VC++ project?

#include <iostream>

using namespace std;

int main()
{
    cout << "Д  |" << endl; 
    return 0;
}

You could probably also look into unicode literals with C++11 in this area.

There is also std::wcout, std::wcin, std::wstring, but you might wanna look into ICU. That is also what Qt is using in general.

Community
  • 1
  • 1
László Papp
  • 51,870
  • 39
  • 111
  • 135