Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TEdit, CString and Double cast 1

Status
Not open for further replies.

bateman23

Programmer
Mar 2, 2001
145
DE
I think this is a very simple question, but due i'm new to c++ and even newer to borland c++ :), here i go:
How do i convert a input of a TEdit-field to a double ?

I searched a little and found this sample of code:
CString string;
double thedouble;
thedouble = atof((LPCSTR)string);

but i even can't define a cString (and yes, i already did &quot;include <cstring.h>&quot;)
Is there anybody out there who can help me ?

Thanx in advanced,
Daniel ---------------------------------------
Visit me @:
 
I don't know much about VC++ but,

could the AnsiString be the solution ?
 
CString....i interpete it as &quot;C-String&quot;. i.e. an array of char's and it can be declared as:

char string[Length+1]; // The '+1' allows for End-Of-String marker Totte
 
Yes, i meant C-String... BUT
i tried char temp_p[20] = txtp->Text; (txtp is a TEdit-Control) to get the content of the Text-field into an array.
But i just got the error-message: &quot;Can't convert ANSI-String to char[20]&quot;!

So instead i tried:
String temp_p;
temp_p = txtp->Text;


This worked, but then converting this string to double didn't work:
p = atof((LPCSTR)temp_p);
gave the error-message: &quot;Cast from ANSI-String to const char not possible&quot;...

---------------------------------------
Visit me @:
 
Try this:
Code:
String MyString = &quot;3.14&quot;;
double TheDouble = 0;

// do conversions in a try ... catch statment just in case
try
{
    TheDouble = StrToFloat(MyString.c_str());
}
catch (...)
{
   // Opps there was an error
   // Handle it here
}

You could also try ToDouble. James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top