String to floating point conversion problem

I'm making an application in C++, using Windows Forms in Visual Studio 2008. I need to get a decimal number from a text box, but since it returns a string, I have to convert it to float.

After some research, I discovered the atof() function, plus several others.

However, when implemented, it produces an error, whose cause I do not understand.

For example, the following piece of code:

float f = atof ( textBox->Text );

Generates the following error:

Error 1 error C2664: 'atof' : cannot convert parameter 1 from 'System::String ^' to 'const char *'

It seems to try to get a const * char out of the string, then proceed to convert it to a float, but for some reason the conversion to const * char fails.

Does anyone know what the problem is?
It's because you can't convert it directly. I know std::string's have a .c_str() method to get a char* out of them, so you could try that.
closed account (z05DSL3A)
As you are doing .net (Windows Forms), you should use the .net framework to do the conversion:
1
2
String^ strNumber = "2.456";
double dbl = Convert::ToDouble(strNumber);
Grey Wolf's method worked perfectly!

Thank you all for the help!
Topic archived. No new replies allowed.