|
If you are not filtering the allowable characters in the edit control, you may have cases where users enter data that cannot be converted to a double. For example, 12345.65a , abc123 , 123..4 , etc.
While I would suggest getting the text from the control and then converting it to a double, I would use strtod(...) /_tcstod(...) /wcstod(...) instead. It provides a way to tell you what character causes conversion to fail, which can be used to provide automatic error handling (i.e. ignore any invalid characters), or to provide a more helpful error message to the user.
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks James. But still not to the mark. Actually I want to convert CString to int. So, based on your hint, I opted to use strtol and then cast it to int, as i didn't find any method that converts strtoi.
CString csValue;
GetDlgItem(IDC_OpNo_EDIT)->GetWindowText( csValue );
LPTSTR p = csValue.GetBuffer(10);
char* stopString;
long l = strtol(p, stopString, 9);
csValue.ReleaseBuffer();
double d = atof((LPCTSTR)csValue);
The error is :
: error C2664: 'strtol' : cannot convert parameter 1 from 'unsigned short *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
atof also gives the same error.
aNY WAY to convert LPTSTR ot CString to char*, TCHAR* or wCHAR*.
Thanks
Terry
|
|
|
|
|
Change the function to wcstod or _tcstod, if you are straight Unicode or TCHAR-based building as Unicode, respectively.
PEace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
See here.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
#include "iostream.h"
int x = 10;
int main()
{
int x = 8;
{
int x = 5;
cout << x << ::x ;
}
return 0;
}
|
|
|
|
|
yes, that's what cout << x does you updated your post, so now, the answer is no.
you can only access a most inner variable (by using its name) or accessing the global variable by prepending its name with the global scope operator ( :: ).
|
|
|
|
|
As posted you question is ambiguous.
Anyway the following one is clear
Super Hornet wrote: //can we access the value of x which is defined as int x = 8 here?
and the answer is (AFAIK ) no: the inner x hides the outer one.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
No you Can't the value with ::x will be the value from the global namespace.
-@SuDhIrKuMaR@-
|
|
|
|
|
Super Hornet wrote: //can we access the value of x which is defined as int x = 8 here?
If you badly need it then rename inner x to something else or store the previous x(main) in some variable before you declare the most inner x and use that variable.
This is not the optimal way for naming variables. You can easily give different names. Or is this an interview question?
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
#include "iostream.h"
int x = 10;
int y;
int main()
{
int x = 8;
y = x;
{
int x = 5;
cout << x << ::x ;
USE Y! ;)
}
return 0;
}
In other words, NO. You cannot do it.
OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus
Best wishes to Rexx[^]
|
|
|
|
|
You may use namespaces to avoid collisions.
#include<iostream>
namespace Global
{
int x = 0;
namespace inner
{
int x = 2;
}
}
int main()
{
int x = 1;
{
int x = 4; cout<<"This is from within a brace "<<x<<endl;
}
cout<<"Global::x"<<Global::x<<endl;
cout<<"x"<<x<<endl;
cout<<"Global::inner"<<Global::inner::x<<endl;
return true;
}
<div class="ForumSig"> <font size="1.5" face="verdana" color="blue<br" />
<font face="Verdana" color="burgundy" size="1.4">Nobody can give you wiser advice than yourself. - Cicero</font>
<font color="navy" size="1.4">.·´¯`·->Rajesh<-·´¯`·.</font>
<font color="maroon">Codeproject.com: Visual C++ MVP</font></div>
|
|
|
|
|
Its an interview question by Microsoft and thank you for the answers
|
|
|
|
|
I created a Dialog box in that i want to create 3 pages
|
|
|
|
|
you mean tabs ?
create a PropertySheet with 3 PropertyPages...
|
|
|
|
|
can u please give sample code i am new to VC
|
|
|
|
|
Member 4655685 wrote: can u please give sample code i am new to VC
sure. download the source of the VisualCalc[^] project, and see how the "Help" dialog is built...
|
|
|
|
|
Pages? Are you talking about a Tab Control ?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
no not tab control property sheets
|
|
|
|
|
So see my reply.
|
|
|
|
|
|
yes its urgent i am new to VC
|
|
|
|
|
Member 4655685 wrote: yes its urgent
urgenz query is of da azk pleaz in http://www.rentchacod3rz.com[^]
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
sorry ur link is not working
|
|
|
|
|
|
My reply was a sarcastic note / joke (look at the rant icon).
The point is that, you should not ask "urgent" queries here. This is because people from all timezones visit this forum and they may take their own time to answer your query. They may have their own work and they'll answer queries here on this board, when they have the time for it. There's a lot more to say, but Pete has penned down an excellent article, which I highly recommend you to read. That will surely be helpful to you. ForumGuidelines[^]
Also, read the sticky post at the top of first page on this board, which says "How to get an answer to your question".
Last but not least, welcome to the CodeProject community.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|