PDA

View Full Version : ASCII to int and int to ASCII



askbapi
31st March 2010, 22:03
How cam I get ASCII value (int) of each character of "QString" and again change it back into Characters ?

Native code - ASCII value of character
-----------------------------------
char str[21];
str[]="Good boy";
for(i=0;i<=20;i++)
{
cout << int(str[i]);

}

Lykurg
31st March 2010, 22:34
char str[21];
str[]="Good boy";
for(i=0;i<=20;i++)
{
cout << int(str[i]);

}
Did you lear anything from your last post??? And please use the documentation of QString. All answers can be found there: QChar::unicode().

Lykurg
31st March 2010, 22:36
... but since you don't use Qt in your example, simply use C++:
int x = (int) str[0] - '0';