Int to char conversion
-
I think it can be done with a cast.
Something like that:char a = (char)i;
Hope it works.
Regards.
-
[quote author="BelenMuñoz" date="1359030558"]
char a = (char)i;
[/quote]This is a C style cast and in C++ code it is high recommend to use static_cast. Example:
@
int nMyInt = 65;
char nMyChar = static_cast<char>(nMyInt);
QChar char(nMyChar);
@ -
[quote author="Andre" date="1359033121"]As QChar has a constructor that takes an int, the intermediary cast to char is not needed.[/quote]
Yes, of course. I just wanted to highlight the recommended usage of static_cast instead of the C style cast :)
-
[quote author="Andre" date="1359033597"]I'd say that avoiding the cast altogether is preferable to a static_cast, which is preferable over a C style cast :-)[/quote]
(y) Absolutely :)
-
[quote author="leon.anavi" date="1359033022"]
[quote author="BelenMuñoz" date="1359030558"]
char a = (char)i;
[/quote]This is a C style cast and in C++ code it is high recommend to use static_cast. Example:
@
int nMyInt = 65;
char nMyChar = static_cast<char>(nMyInt);
QChar char(nMyChar);
@
[/quote]Thanks for the reply, I still have bad habbits from C.