Converting AnsiString to double

F

Franz Seidl

Hello,

how can i convert a AnsiString to double?

I'm using C++ Builder 5 from Borland...

Greets,
Franz
 
G

Greg

Franz said:
Hello,

how can i convert a AnsiString to double?

I'm using C++ Builder 5 from Borland...

Greets,
Franz


how about:

#include <iostream>
#include <string>
#include <sstream>

int main()
{
std::string pi("3.1459");

std::stringstream s(pi);
double d;

s >> d;

std::cout << "d is " << d << std::endl;
}

output:
d is 3.1459

Greg
 
F

Franz Seidl

Hello Greg,

is there a way to use a AnsiString (sorry but normally I'm
programming in Delphi, PHP, C#)?

Greets,
Franz
 
R

red floyd

Franz said:
Hello Greg,

is there a way to use a AnsiString (sorry but normally I'm programming
in Delphi, PHP, C#)?

Greets,
Franz
Ask in a borland newsgroup.
 
J

John Harrison

Franz said:
I was searching for it before. But my newsserver has only a pascal
newsgroup from borland... :(

Greets,
Franz

Does AnsiString have some method to convert to a C string? I'm sure it does.

If so then you can use the sscanf function

AnsiString a = "12.34";
double d;
sscanf(a.some_method_to_convert_to_a_C_string(), "%lf", &d);

john
 
F

Franz Seidl

Hello John,

John said:
Does AnsiString have some method to convert to a C string? I'm sure it
does.

If so then you can use the sscanf function

AnsiString a = "12.34";
double d;
sscanf(a.some_method_to_convert_to_a_C_string(), "%lf", &d);

Yes, you are right. There are a function called "a.c_str()"...

Thank you!

Greets,
Franz
 
D

DJ Franke

Hi !

The Borland IDE is full of helpfull hints. Press F1 with the cursor on
the text 'AnsiString' and you will find the '.ToDouble()' function
under methods in the help menu.

Have fun
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top