if i initialize x=65. it can show A (ascii code 65 is A). but 167 cannot.. why?

#include <iostream>
using namespace std;

main()
{
      char x=167;
      cout<<x<<endl;
      system("pause");
      return EXIT_SUCCESS;
}

. but 167 cannot.. why?

Not sure what you mean "but 167 cannot...why?"

Cannot show A?

i mean if initialize char x=65, cout<<x; will show 'A'
but if i initialize char x=167, cout<<x; it doesnt show any thing...

when you write a program, you express C source files as text lines containing characters from the source character set. when a program executes in the target environment, it uses characters from the target character set. these character sets are related, but need not have the same encoding.

this is all that you can assume:
every character set must contain a distinct code value for each distinct character in the basic C character set. the code value zero is reserved for the null character (and is always in the character set). code values for the digits are contiguous, with increasing values for characters from '0' to '9'. code values for any two letters (eg. 'a' and 'b') are not necessarily contiguous. code values for the basic C character set are positive when stored in an object of type char.

you can change locales and, therefore, target character sets while the program is running (by calling the function setlocale). the translator encodes character constants and string literals for the default "C" locale ( 'classic' locale in C++ ) which is the locale in effect at program startup.

> if i initialize x=65. it can show A
this is not guaranteed in any way. 65 may not be a code value in the target character set at all, or it may be the code value for some other character. you just happen to be running in a target environment where code value 65 maps to an 'A'.

> but 167 cannot.. why?
167 may be larger than std::numeric_limits<char>::max() on the target environment (eg. i386),
or even if it is a positive value that can be held in a char, 167 may not be a code value for any character in the target character set.

if you want a character to be displayed as an 'A' in the target environment, initialize it this way: char x = 'A' ; . and use the default locale while displaying it.

It could be that 167 is an extended ascii character

So u mean there r no way to show the extended code(167)?

> So u mean there r no way to show the extended code(167)?

i mean that there is no *portable* way to show the extended code(167).
or any specific numeric code value (like 65) for that matter.

there are non-portable ways. for example, you could use the SetConsoleOutputCP function on windows. http://msdn2.microsoft.com/en-us/library/ms686036(VS.85).aspx

ok thx...

If you are using MS-DOS or MS-Windows you can draw lines draw extended ascii codes See the chart for other line-drawing characters. The other characters will not appear on your screen or show up as small circles/squares because most fonts don't use them for anything.

Simple example:

int main()
{
    char array[80];
    memset(array,205,80);
    array[79] = 0;
    cout << array << "\n";
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.