Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Superscript in C++ console output

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

How do make a superscript 2?

like image 867
rectangletangle Avatar asked Oct 27 '10 22:10

rectangletangle


Video Answer


2 Answers

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;
}
like image 71
Matthew Flaschen Avatar answered Nov 13 '22 01:11

Matthew Flaschen


This is not something C++ can do on its own.

You would need to use a specific feature of your console system.

I am not aware of any consoles or terminals that implement super-script. I might be wrong though.

like image 26
Zan Lynx Avatar answered Nov 12 '22 23:11

Zan Lynx