C ++控制台输出中的上标 [英] Superscript in C++ console output

查看:79
本文介绍了C ++控制台输出中的上标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让程序输出"cm 2 "(平方厘米).

I'd like to have my program output "cm2" (cm squared).

如何制作上标2?

推荐答案

这取决于标准输出支持哪种编码字符.如果它支持Unicode,则可以将编码用于²( U + 00B2 ).如果它为源文件和标准输出支持相同的Unicode编码,则可以将其嵌入文件中.例如,我的GNU/Linux系统对两者都使用UTF-8,因此可以正常工作:

As Zan said, it depends what character encoding your standard output supports. If it supports Unicode , you can use the encoding for ²(U+00B2). If it supports the same Unicode encoding for source files and standard output, you can just embed it in the file. For example, my GNU/Linux system uses UTF-8 for both, so this works fine:

#include <iostream>

int main()
{
    std::cout << "cm²" << std::endl;
}

这篇关于C ++控制台输出中的上标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆