2

I need to put out a single char, but codepage my system using doesn't have that symbol (i.e. spanish exclamation point "¡"). Trying

char excl = 173; 
cout.put(excl);

but it types another symbol.

Alex.S
  • 33
  • 7

2 Answers2

3

If the settings of the operating system are not configured to the approriate codepage you first have to set the locale:

setlocale( LC_ALL, "esp" );

This sets your locale to Spanish_Spain.1252 (Windows-1252) Then the character is under the value 161

char excl = 161;
std::cout.put( excl );

std::setlocale

The setlocale function installs the specified system locale or its portion as the new C locale. The modifications remain in effect and influences the execution of all locale-sensitive C library functions until the next call to setlocale.

Explaination of constants:

  • LC_ALL : selects the entire C locale
  • LC_COLLATE : selects the collation category of the C locale
  • LC_CTYPE : selects the character classification category of the C locale
  • LC_MONETARY : selects the monetary formatting category of the C locale
  • LC_NUMERIC : selects the numeric formatting category of the C locale
  • LC_TIME : selects the time formatting category of the C locale
Robert Andrzejuk
  • 5,076
  • 2
  • 22
  • 31
0

What finally worked was

SetConsoleCP(1252);
SetConsoleOutputCP(1252);

Probably because I reinstalled VC++ and chose only English language pack during installation.

Alex.S
  • 33
  • 7