Connecting Tech Pros Worldwide Help | Site Map

convert string to float

  #1  
Old July 23rd, 2005, 01:50 AM
Juhan Voolaid
Guest
 
Posts: 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.
  #2  
Old July 23rd, 2005, 01:50 AM
Sumit Rajan
Guest
 
Posts: n/a

re: convert string to float



"Juhan Voolaid" <jux@hot.ee> wrote in message
news:cuna0d$7pr$1@kadri.ut.ee...[color=blue]
> Hi
>
> I'm having hard time finding a way to convert:
>
> std::string input="10.5";
> to
> float input2;
>[/color]

Try this link:
http://www.parashift.com/c++-faq-lit...al-issues.html
--
Sumit Rajan <sumit.rajan@gmail.com>


  #3  
Old July 23rd, 2005, 01:50 AM
Ron Natalie
Guest
 
Posts: n/a

re: convert string to float


Juhan Voolaid wrote:[color=blue]
> Hi
>
> I'm having hard time finding a way to convert:
>
> std::string input="10.5";
> to
> float input2;[/color]

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;
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert String to float and still retain the precision tumblypooh answers 5 October 29th, 2008 07:54 PM
how do i convert string to float in c#??? tomerd11 answers 1 August 24th, 2007 10:33 AM
convert string to float Chi Tang answers 2 November 15th, 2005 07:33 AM
How to convert string to float? Jason Chan answers 4 July 19th, 2005 08:05 AM