Solved

Converting a String into double?

Posted on 2004-08-10
5
10,967 Views
Last Modified: 2010-04-24
How is a String converted into double in Visual C++ .NET?
0
Comment
Question by:judico
  • 3
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 125 total points
ID: 11762596
Is this managed or unmanaged C++?

Managed version:

    System::String *strd = S"123.456";
    double val = System::Double::Parse(strd);


Unmanaged version:

    std::string strd("123.456");        // You could use regular char[] instead
    double val = ::atof(strd.c_str());
   
0
 

Author Comment

by:judico
ID: 11763021
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 []'

0
 
LVL 19

Expert Comment

by:drichards
ID: 11763149
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);
0
 

Author Comment

by:judico
ID: 11763293
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.
0
 
LVL 19

Expert Comment

by:drichards
ID: 11763327
You're welcome.  Thanks for the extra points.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
preprocessor definition in visual studio 2 197
auto dialer software c# 1 75
Pointers - Drive letter 1 70
What is the real difference between C++ and Visual C++.NET? 7 120
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question