Link to home
Start Free TrialLog in
Avatar of Saeed Vaezi
Saeed Vaezi

asked on

working with numbers in editbox in mfc c++ application

Hello dear experts
I have a editbox in mfc dialog based application.
user must enter a long number in editbox (like 123456789123456789) and the application must make some calculations on it and then show it to user on another editbox.
how can I convert CString to long int and after calculation again convert long int to CStirng to pass to next editbox.
thank you
SOLUTION
Avatar of Ares Kurklu
Ares Kurklu
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sarabande
you also can use std::stringstream

#include <sstream>

....

CString strNumber = "123456789123456789";
std::istringstream iss((const char *)strNumber);
long long number = -1;
if (!(iss >> number))
{
     //error string is not numeric
     return;
}
// and back to CString
std::ostringstream oss;
oss << number;
strNumber = oss.str().c_str();

Open in new window

Avatar of Saeed Vaezi
Saeed Vaezi

ASKER

It was very easy
for converting CString to long long int just use _wtoll() function
and for converting long long int to CString again just define a temporary CString like:
CString tempstr;
tempstr.format(L"%lld",your long long int);
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if i would have been asked to close the question, I would have recommended an equal split between #a42473406 (assist) and #a42473791 (accept).

but the comment of the Questioner showed that neither solution actually was looked on, let alone tested. by providing an own solution (which is inferior to the given solutions) we have the case that a simple thread which had two suitable answers now had become complex and rarely useful for the knowledgebase.

so, my recommendation is to delete the question.

Sara
I'm new in c++ and mfc. thanks for your answer but I tested your answer on New project in visual studio 2017 mfc project and it not working (I don't know why can you help me why?). But my problem resolved with comment I posted. _wtoll() is exactly spelled like this.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
There are two valid solutions and the Autor gave feedback. I recommend to close the question with an equal split although we didn't get a final response that the solutions have worked.

Sara