2

I am trying to get the unicode character macron (U+00AF), i.e., an overscore, to print consistently on various linux consoles. So far, some consoles work (e.g., putty ssh), others do not (e.g., ubuntu shell), and I have not been able to figure out what I am doing right in one case (probably luck) and wrong in the other.

I do know the basics of Unicode and Utf8, but I have not been able to figure out how to consistently get consoles to display the appropriate characters.

Any suggestions? Note that this is explicitly for unix consoles - all of the similar questions I have found focused on Windows-specific console commands.

Here is what I would effectively like to get working:

wchar_t post = L'¯'; //0xC2AF
std::wcout << post << std::endl;
zennehoy
  • 6,405
  • 28
  • 55
  • This might help: http://stackoverflow.com/questions/1799063/how-can-i-display-unicode-characters-in-a-linux-terminal-using-c Specifically -export LC_ALL=en_US.UTF-8 – Eejin Feb 27 '14 at 12:39

2 Answers2

1

Unfortunately nothing I tried or could find in the way of suggestions consistently displayed the appropriate character, so I ended up using an ASCII hyphen '-' as a close enough match.

zennehoy
  • 6,405
  • 28
  • 55
0

The solution is to put it into stream as a multicharacter string:

std::string s = "\uC2AF";
std::cout << s << std::endl;

or to set a locale using

char* setlocale( int category, const char* locale);

function:

std::locale old_locale;  // current locale
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t w = 0xC2AF;
std::wcout << w << std::endl;
setlocale(LC_ALL, old_locale.name().c_str());  // restore locale

The final result is however dependent on many user settings (console, fonts, etc.), so there is no guarantee that it will be OK.

4pie0
  • 29,204
  • 9
  • 82
  • 118