How to write "Ni Hao" ("Hello") in Chinese to standard output using UTF-8 in C++

1 Answer

0 votes
#include <iostream>
#include <locale>

int main() {
    // Set the locale to UTF-8
    std::locale::global(std::locale("en_US.UTF-8"));

    std::wcout.imbue(std::locale());
    std::wcout << L"你好" << std::endl;

    return 0;
}



/*
run:

你好

*/

 



answered Aug 14, 2025 by avibootz
...