【问题标题】:How to print subscripts/superscripts on the screen in C++?如何在 C++ 的屏幕上打印下标/上标?
【发布时间】:2010-06-07 17:39:23
【问题描述】:

是否可以打印下标/上标? 例如像这样:x² 有哪些功能可以做到这一点?

【问题讨论】:

  • 这与 C++ 无关,与您正在使用的控制台/终端有关。
  • 什么操作系统?什么环境?网络? Linux?安慰?窗户?

标签: c++ printing


【解决方案1】:

这完全取决于您运行的环境。对于 GUI 系统(Windows、Mac、Qt 等),您需要查阅 API 文档。对于文本模式系统,您能做的最好的事情就是在当前编码中使用特定字符。例如,unicode 有某些code points 是其他字符的上标或下标。

【讨论】:

    【解决方案2】:

    如果您使用的是 GUI,则可以更改字体的大小和方向。

    还有superscript and subscript characters 可以使用Unicode。

    【讨论】:

      【解决方案3】:

      您可以根据区域设置打印适当的 Unicode 符号到 cout 或 wcout:

      #include <iostream>
      int main()
      {
              std::cout << "x\u00b2" << std::endl;
      }
      

      #include <iostream>
      #include <locale>
      int main()
      {
              std::locale::global(std::locale("de_DE.UTF8"));
              std::wcout << L"x\u00b2" << std::endl;
      }
      

      【讨论】:

        猜你喜欢
        • 2014-03-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多