print ‘Ø’ and ‘𦍏’ in c++?

huangapple go评论167阅读模式
英文:

print 'Ø' and '𐌟' in c++?

问题

我尝试使用 wchar_t,但它会产生警告并在终端中打印奇怪的字符。\n直接打印会得到相同的结果\n\n cout<<Ø<< <<𐌟;\n\n输出:\n\n ├ÿ ≡Éîƒ

英文:

I tried using wchar_t but it gave a warning and print weird characters in the terminal.
or printing directly gave the same result

  1. cout&lt;&lt;&quot;&#216;&quot;&lt;&lt;&quot; &quot;&lt;&lt;&quot;&#66335;&quot;;

gives output:

  1. ├&#255; ≡&#201;&#238

答案1

得分: 2

  1. #include <string>
  2. #include <iostream>
  3. #include <Windows.h>
  4. #include <cstdio>
  5. int main(){
  6. SetConsoleOutputCP(CP_UTF8);
  7. setvbuf(stdout, nullptr, _IOFBF, 1000);
  8. std::cout << "Ø" << " " << "極";
  9. }
英文:
  1. #include &lt;string&gt;
  2. #include &lt;iostream&gt;
  3. #include &lt;Windows.h&gt;
  4. #include &lt;cstdio&gt;
  5. int main(){
  6. // Set console code page to UTF-8 so console known how to interpret string data
  7. SetConsoleOutputCP(CP_UTF8);
  8. // Enable buffering to prevent VS from chopping up UTF-8 byte sequences
  9. setvbuf(stdout, nullptr, _IOFBF, 1000);
  10. std::cout&lt;&lt;&quot;&#216;&quot;&lt;&lt;&quot; &quot;&lt;&lt;&quot;&#66335;&quot;;
  11. }

I got the answer, It prints the value as expected

huangapple
  • 本文由 发表于 2023年6月8日 00:55:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76425549.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定