3

I'm trying to make a code where I make Lenny jump, but lenny's face this: ( ͡° ͜ʖ ͡°)

When compile & run the code (g++ -o Lenny main.cpp), I get the output "( ͡° �~\�~V ͡°)". Is there a way I can get it to display ( ͡° ͜ʖ ͡°)?

Cubbi
  • 46,567
  • 13
  • 103
  • 169
Predictability
  • 2,919
  • 4
  • 16
  • 12
  • http://codepad.org/z6MnmwcD – Predictability Dec 03 '12 at 04:38
  • @Predictability It's best to include the source code in your Stackoverflow posts. You could make a minimal complete program that prints just that one problematic line, it would have made the actual fix obvious. – Cubbi Dec 03 '12 at 17:41

2 Answers2

0

You are dealing with Unicode characters. You can use this libray: ICU.

See more here:

Community
  • 1
  • 1
rendon
  • 2,323
  • 1
  • 19
  • 25
0

Linux has good Unicode support, you don't need any special libraries if all you're doing is output:

#include <iostream>
int main()
{
    std::cout << "( ͡° ͜ʖ ͡°)\n";
}

online demo: http://ideone.com/UUS6Il

Or, you could not rely on Linux's built-in UTF-8 and be explicit about it:

#include <iostream>
#include <locale>
int main()
{
    std::locale::global(std::locale("en_US.utf8"));
    std::wcout.imbue(std::locale());
    std::wcout << L"( ͡° ͜ʖ ͡°)\n";
}

online demo: http://ideone.com/EhTfB9

EDIT: Based on your code in the comment, your question is actually about the ncurses library I/O, not about C++. To get your program work as expected,

  1. Add the line setlocale(LC_ALL, "en_US.utf8"); near the beginning of your main() (and add #include <clocale> accordingly)
  2. change your linkline to use -lncursesw as opposed to -lncurses if that's what you're using.
Cubbi
  • 46,567
  • 13
  • 103
  • 169