Connecting Tech Pros Worldwide Help | Site Map

convert string to float

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 12:50 AM
Juhan Voolaid
Guest
 
Posts: n/a
Default convert string to float

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, 12:50 AM
Sumit Rajan
Guest
 
Posts: n/a
Default 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, 12:50 AM
Ron Natalie
Guest
 
Posts: n/a
Default 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;
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.