must you convert from strings to double? if so. how?
Are there functions for trig that will accept textbox string data as is?
Is there a way to pull the data from the textbox as a numeric value, not as a string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes.
The C++ way is to use the string streams; in particular, you’ll probably want to use
istringstream. A viable alternative is to follow the C way, i.e. usesscanfwith the appropriate format specifier (“%f”).Another C++ option is to use the boost
lexical_cast, but starting to use boost just forlexical_castis a bit overkill in my opinion.Example with
istringstream:AFAIK no, there’s no need of them (although you can write them quite easily).
The WinAPIs provide a handful of such “convenience functions” for use in dialogs, but the only one I can recall that provides such help is
GetDlgItemInt, which, as the name may suggest, works only for integers.Addendum
I see now that you are using C++/CLI (you mentioned System::String): well, you should have said that, this changes the options quite a bit.
In the managed world, your best option is to use the
Double::Parsemethod; to catch bad-formatted strings, you should either catch the exceptions thrown byDouble::Parseor callDouble::TryParsebefore callingDouble::Parse.Addendum bis
Uh, I forgot, since you’re using the .NET Framework probably it should be better to use the .NET trigonometric functions (class
System.Math).