Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to give numerical Input from Edit Box and Inside the code I want to read the value which I have given.

If I use getwindowText It's getting as a CString , but I want as a int.


Does anybody know ??
Posted

In addition to what Jochen said you might like to consider using std::stringstream or std::strstream to do the conversion. Despite being deprecated in 1998 [1] strstream is quite good at this sort of thing as you don't need to copy the data. Something like:

C++
int number = 0;
std::strstream( number_string.GetString() ) >> number;


where number_string is a CString works quite well.

[1] But it still hasn't been removed from the standard, probably 'cause people like me like it around for extracting data from fixed size buffers.
 
Share this answer
 
Comments
Baaki 29-Oct-14 5:58am    
Thanks a lot
The C standard library provides two functions to convert strings to integers: atoi[^] and strtol[^].

Example:
C++
CString str = control.GetWindowText();
int n = _tstoi(str.GetString());
 
Share this answer
 
Comments
Baaki 29-Oct-14 5:58am    
Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900