Link to home
Start Free TrialLog in
Avatar of snellejelle
snellejelle

asked on

getting a double from an AnsiString

I'm quite new at C++, and working with borland builder 5.5.
I am trying to get a float from an Edit, but the Edit returns an AnsiString when i use Edit2->Text. Is it possible to cast it to a double, or should i try something different? (and what?)
Thanx
Avatar of EOL
EOL

with AnsiString you mean a cString (or M$ calls them LPCSTR )

You do you can get a float from the string with the function float atof( char * ). example:
float test = atof("1234.04");

If you mean std::string with AnsiString it's not that easy, but much nicer. For formatted input and output you need a stream. for string you need the stringstream.

#include <string>
#include <sstream>
stringstream ss;
ss << string( "1234.05" );
float test;
ss >> test;

As you can see you can construct the string from the cString easely.
ASKER CERTIFIED SOLUTION
Avatar of sdyx
sdyx

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
Yes, there is a CString class by M$, which nobody uses. There is however also the c-String which refers to a char array with trailing zero ( hence the name c-String ). From my usage it should be obious what I meant with cString.

Intresting, didn't know Borland has it's own String class. I would use STL instead, but that's up to you of course.
Avatar of snellejelle

ASKER

thnx a lot!