1

I am using repl.it to edit and compile some C++ code. I want to output the obelus (division sign) to the console. The following code should do it.

char div_sign ='\366';
cout << div_sign << endl;

This works in Visual Studio and from what I can find out it should work with any compiler. However, I do not get the correct output. The only thing I can think of is the repl does not use the OEM character set. Any suggestions to get this to work correctly in repl?

Mikel Rychliski
  • 3,455
  • 5
  • 22
  • 29
user2970381
  • 93
  • 3
  • 11

1 Answers1

0

The only thing I can think of is the repl does not use the OEM character set

This is correct.

\366 (0xF6, 246) is the character code for ÷ in the OEM-US/CP437 codepage.

repl.it treats what you write to std::cout as UTF-8. The Unicode codepoint for the same character is \367 (0xF7, 247).

Encoding that to UTF-8 gives us:

  std::cout << "\303\267";

which gives the expected output on repl.it

Mikel Rychliski
  • 3,455
  • 5
  • 22
  • 29
  • Is there a general way to get something to work for all runtime environments so we don't need to change the code to get it to work both places? – Jerry Jeremiah Apr 16 '20 at 09:53