Can you input squared symbols?

I was just wondering if it is possible to display the ^2 symbol and the square root symbol. I tried to copy and paste from another site and it gives me a weird striped box in the displayed product.
Thank you.
Testing square root symbol: √ (U+221A) works just fine for me.

Couldn't find a 'square' glyph.


EDIT: seems to work just fine.

EDIT 2: Did you mean on the forums? Or in a program?
Last edited on
I was looking to do this in a program.
closed account (28poGNh0)
1
2
3
4
5
6
7
8
9
10
# include <iostream>
# include <cmath>
using namespace std;

int main()
{
    cout << char(251) << "5 = " << sqrt(5) << endl;

    return 0;
}
Output from a program may depend on system setup, you will have to tell us what OS you're using.

On systems that provide Unicode support to C++ programs (that means not Windows), it's as easy as this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <locale>

int main()
{
    // using system narrow character encoding
    std::cout << "3² = 9\n"
              << "√9 = 3\n";
    // using system wide character encoding
    std::wcout.sync_with_stdio(false); // or set the C locale too
    std::wcout.imbue(std::locale(""));
    std::wcout << L"3² = 9\n"
               << L"√9 = 3\n";
}

online demo: http://ideone.com/6CheA6

could also write that as "3\u00b2 = 9\n" and "\u221a9 = 3\n"
Last edited on
Topic archived. No new replies allowed.