Superscript in C++ console output

rectangletangle picture rectangletangle · Oct 28, 2010 · Viewed 21.4k times · Source

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

How do make a superscript 2?

Answer

Matthew Flaschen picture Matthew Flaschen · Oct 28, 2010

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