rectangletangle rectangletangle - 2 months ago 35
C++ Question

Superscript in C++ console output

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

How do make a superscript 2?

Answer

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;
}
Comments