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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
Intresting, didn't know Borland has it's own String class. I would use STL instead, but that's up to you of course.
ASKER
thnx a lot!
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.