0

As far as normal ascii is concerned can I compare a wchar_t with a char type to see if they are equal?

I think, but do not know, that the most common ASCII chars have the same integer value in char and wchar_t. Is that true? Do I need to be careful?

The application I'm writing will also compare punctuation like , . : ; \t \n

Summarising, in UNICODE c++ when is this valid:

wchar_t wcA = ...
char chB = ...
if (wcA == chB) {
    ...
}
5
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by owenransen
0

I think that in the conditional expression the 8 bits variable gets promoted to a 16 bits wchar_t.

Edited by caut_baia: n/a

0

I agree with caligulaminus, that with ASCII it will not give problem. Since ASCII need 1 byte for its representation. But if you talk about UNICODE content, then its not advisable to do so. Because UNICODE may use multiple bytes for character representation.

0

> Do I need to be careful?

If you decide to be careful, the code would be something like:

wchar_t wc = L'A' ;
    char c = 'A' ;
    const auto& ctype = std::use_facet< std::ctype<wchar_t> >( std::locale() ) ;
    if( ctype.widen(c) == wc ) { /* whatever */ }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.