The symbol I used is
not Unicode. It is in the default Windows Console code page "Extended ASCII Set". Hence my statement that it is for use on the Windows Console, since that is the only place it will display properly.
To find them, check out
http://www.asciitable.com/
If you write your program in Windows and send it to your professor (who may be using Unix or Linux), it will not work for him.
For modern Linuxes, you will want to actually use Unicode by way of UTF-8. You can google into Wikipedia's unicode listings to get pages like
http://en.wikipedia.org/wiki/Mathematical_operators_and_symbols_in_Unicode, which show that the square root symbol to be U+221A. You'll have to convert that to a UTF-8 sequence to print it.
A simplistic way to convert to UTF-8 is to use the Windows Notepad editor. Copy and paste the single character you want into the file and save it as UTF-8. Use the following program to get something you can paste into your program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
using namespace std;
int usage( const char* program_name, int exit_code )
{
cout << "Notepad UTF-8 character file to C++ string converter.\n"
"To use, type:\n\n"
" " << program_name << " FILENAME\n\n"
"at the command prompt, where FILENAME is the name of the Notepad file.\n";
return exit_code;
}
void display( char c )
{
cout << "\\x" << ((int)c & 0xFF);
}
int main( int argc, char** argv )
{
if (argc != 2) return usage( argv[ 0 ], 0 );
ifstream f( argv[ 1 ], ios::binary );
if (!f) return usage( argv[ 0 ], 1 );
f >> noskipws;
istream_iterator <char> fin( f );
advance( fin, 3 ); // skip the stupid Windows UTF-8 BOM
cout << "\"" << uppercase << hex;
for_each( fin, istream_iterator <char> (), display );
cout << "\"\n";
return 0;
}
|
Running the program gets me the string
"\xE2\x88\x9A"
, which is the UTF-8 sequence to print U+221A on your Linux console.
Finally, use a simple #define to tell the systems apart:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include <iostream>
using namespace std;
#ifdef _WIN32
const char sqrt_symbol[] = "\xFB";
#else
const char sqrt_symbol[] = "\xE2\x88\x9A";
#endif
int main()
{
cout << sqrt_symbol << "9 = 3\n";
return 0;
}
|
Your professor will be OK with that.