PDA

View Full Version : How to convert string into const int ?



babygal
16th July 2010, 08:56
How to convert string into const int ?

dpatel
16th July 2010, 09:01
Try this



const int myInt=myString.toInt();

babygal
16th July 2010, 11:49
Try this



const int myInt=myString.toInt();



It works!

But strangely if I do it the way as shown in code below, I will get error: assignment of read-only variable myInt .

const int myInt = 0;

myInt = myString.toInt();

dpatel
16th July 2010, 11:57
That is an expected behavior, since consts can be assigned value only once. In your case you use your one chance when you assign 0 to it. After that it become read-only.