By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,898 Members | 2,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,898 IT Pros & Developers. It's quick & easy.

convert string to float

P: n/a
Hi

I'm having hard time finding a way to convert:

std::string input="10.5";
to
float input2;

help is appreciated,
Juhan Voolaid.
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Juhan Voolaid" <ju*@hot.ee> wrote in message
news:cu**********@kadri.ut.ee...
Hi

I'm having hard time finding a way to convert:

std::string input="10.5";
to
float input2;


Try this link:
http://www.parashift.com/c++-faq-lit...al-issues.html
--
Sumit Rajan <su*********@gmail.com>
Jul 23 '05 #2

P: n/a
Juhan Voolaid wrote:
Hi

I'm having hard time finding a way to convert:

std::string input="10.5";
to
float input2;


There are two ways. C gives you strtod which converts between a char array
and double:
input2 = strtod(input.c_str(), NULL);

The C++ streams provide nice conversions to and from a variety of types.
The way to use strings with streams is to use a stringstream:

istringstream in(input);
input >> input2;
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.