extended ascii and istream& getline (char* s, ...

Hi all,
If I want to deal with extended ascii, i.e. from 128 to 255, shall I use char or unsigned char ? If I shall use unsigned char, how to make it compatible with standard libs functions like stream& getline (char* s, ...) ?
Is there anything like unsigned char?

cout<<(char)<code>

Thats it.
If you had an unsigned char array you could just cast it inside the call to getline: getline((char*)uc_array,size);
Pretty sure your unsigned char array will work just fine.
Thanks a lot ! That said, it would have been more logical if the standard library work with unsigned char, including std::string. It is like if the standard does not recognize the extended ascii. I perform algorithmic on extended ascii, and it would be a nightmare to use signed char, thus char.
The standard library recognizes extended ascii just fine, as long as the appropriate locale is installed. The storage type is char/string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <cctype>
#include <clocale>
 
int main()
{
    const char c = '\xdf'; // German letter ß in ISO-8859-1
 
    std::cout << "isalnum(\'\\xdf\', default C locale) returned "
               << std::boolalpha << (bool)std::isalnum(c) << '\n';
 
    std::setlocale(LC_ALL, "de_DE.iso88591");
    std::cout << "isalnum(\'\\xdf\', ISO-8859-1 locale) returned "
              << std::boolalpha << (bool)std::isalnum(c) << '\n';
 
}
isalnum('\xdf', default C locale) returned false
isalnum('\xdf', ISO-8859-1 locale) returned true
Last edited on
Great. Thank you very much Cubbi. This is not directly linked to my original problem, but still very usefull since in my next project steps, you prevent me here from having big headackes.
My use case is char arithmetics for text hashing. Manipulating unsigned char is simpler.
Topic archived. No new replies allowed.