简体   繁体   中英

How can I add a ಠ symbol into my C++ output

I am writing a program for school, and want to include an Easter Egg with the look of disapproval (ಠ_ಠ), however, I do not know what classes in C++ support this character. I would assume this character be included in unicode, but I am not sure how to use that to output into a console application.

If anyone could help me out with this, I would appreciate it. Thanks

Well you need to enable Unicode for your application. For MSVC you can use _setmode(_fileno(stdout), _O_U16TEXT); at the start of your main. But for mingw this is a bit more difficult, see here .

To actually print it you can use the character code and use wcout but be wary!

From: http://www.cplusplus.com/reference/iostream/cout/

A program should not mix output operations on cout with output operations on wcout (or with other wide-oriented output operations on stdout): Once an output operation has been performed on either, the standard output stream acquires an orientation (either narrow or wide) that can only be safely changed by calling freopen on stdout.

You can use \ಠ , that's the Unicode code for this eye thing. Here's a live example:

int main() {
    cout << "hi \u0CA0_\u0CA0";
    return 0;
}

https://ideone.com/QBFtsM

Although IDEOne supports unicode (as in, I can just paste ) so I'm not sure if that will work for you. Let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM