Link to home
Start Free TrialLog in
Avatar of judico
judico

asked on

Converting a String into double?

How is a String converted into double in Visual C++ .NET?
ASKER CERTIFIED SOLUTION
Avatar of drichards
drichards

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
Avatar of judico
judico

ASKER

Thanks for the reply. I still cannot do the conversion. The code is managed and I'm declaring these two arrays (having also -- static int ii ;):

static String *LeSTRING[] = new String*[ 1000 ];
static int Le __gc[] = new int __gc[ 1000 ];

and then, in a loop I'm trying the code you posted above, the way I thought it should be applied in this case:

 System::String *strd = LeSTRING[ ii ];
 double Le[ ii ] = System::Double::Parse(strd);

but I get the error messages:

error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2440: 'initializing' : cannot convert from 'double' to 'double []'
error C2057: expected constant expression
error C2466: cannot allocate an array of constant size 0
error C2440: 'initializing' : cannot convert from 'double' to 'double []'

You're trying to declare Le[ii] as a variable of type double, which won't work.  You can just take the implicit conversion from double to int.  Your code should be (assuming you've assigned actual strings into LeSTRING[]):

 System::String *strd = LeSTRING[ ii ];
 Le[ ii ] = System::Double::Parse(strd);
Avatar of judico

ASKER

Thank you so much for the help. It works very well.

P.S. I increased the points -- let me know if there is any problem.
You're welcome.  Thanks for the extra points.