converting string to unsigned integer
Hi,
Does anybody know how to convert "-2" string to integer?
I have tried doing it as follows but no success....
Is there anything wrong with the following code???
QString s = "-2";
bool ok;
uint m = s.toUInt( &ok, 10 );
Thank you for any help...
Re: converting string to unsigned integer
We figured out how to do it....Here it goes....
QByteArray bArray = s.toLatin1();
const char * ch = bArray.constData();
int m = atoi(ch);
If there is anyother way your welcome to let me know...
Thanks....
Quote:
Originally Posted by mgurbuz
Hi,
Does anybody know how to convert "-2" string to integer?
I have tried doing it as follows but no success....
Is there anything wrong with the following code???
QString s = "-2";
bool ok;
uint m = s.toUInt( &ok, 10 );
Thank you for any help...
Re: converting string to unsigned integer
Quote:
Originally Posted by mgurbuz
uint m = s.toUInt( &ok, 10 );
How about asking for and storing the result in a signed integer aswell? :)
Code:
int m = s.toInt( &ok, 10 );
Re: converting string to unsigned integer
Tell me, how would you like to store a negative number as an unsigned integer? :D As 2^32 - 2? :) Or maybe 2^31? AFAIK -2 is a signed integer...
Re: converting string to unsigned integer
Allright I got it....
I was tried and didn't really read what I wrote....
and tried many things at that time from toUInt ... to... toInt
couldn't make it work.
My question was how to convert a string to signed integer
and as an expert you understand it perfectly....
Quote:
Originally Posted by wysota
Tell me, how would you like to store a negative number as an unsigned integer? :D As 2^32 - 2? :) Or maybe 2^31? AFAIK -2 is a signed integer...