| | |
CString to Integer / Double
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
Hi All,
i have a problem in converting CString to Int/Double,
function i am using is _wtoi , _wtof.....
Here if the CSting value has say "12345"
this works perfectly. But if any other value is say ( Over flow )
" 11111111111111111111111111111" which exceeds
the max size of int then it returns INT_MAX, where as i need the
exact string as int ie 11111111111111111111111111111 in the integer variable. same thing happens in double.
if there is any junk value entered then the ret value is 0,
Please help me in converting the CString to exact int value
i have a problem in converting CString to Int/Double,
function i am using is _wtoi , _wtof.....
Here if the CSting value has say "12345"
this works perfectly. But if any other value is say ( Over flow )
" 11111111111111111111111111111" which exceeds
the max size of int then it returns INT_MAX, where as i need the
exact string as int ie 11111111111111111111111111111 in the integer variable. same thing happens in double.
if there is any junk value entered then the ret value is 0,
Please help me in converting the CString to exact int value
There isn't much you can do about overflows, except just discard the bad CString value. It returns INT_MAX because its impossible to put that many digits into an int variable. I'd like to stuff my 100 inch waste into size 36 slacks too, but that's not possible either
Last edited by Ancient Dragon; Nov 30th, 2008 at 1:29 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Oct 2008
Posts: 35
Reputation:
Solved Threads: 1
Finally i found a way...
When ever any over flow occurs a global variable errno get's set to ERANGE so in the code i have made a check like this
Resetting would give any side effects ?
When ever any over flow occurs a global variable errno get's set to ERANGE so in the code i have made a check like this
C++ Syntax (Toggle Plain Text)
int ConvertToInt( CString intVal ) { int ret = _wtoi(intVla); if((ret == 0) || (errno == ERANGE)) { // Throw Exception // I dont know why i have to do this errno = 0; // If i dont reset the "errno" then the value will be set to //ERANGE even if the next string is valid //I dont know resetting the system variable is correct or not. // Functionality works for me :) } }
Resetting would give any side effects ?
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: stl/map and string question
- Next Thread: Memory allocation (checking for success)
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






