Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


problems with atof

Posted on 2006-04-07
Medium Priority
Last Modified: 2006-11-18

I am having problems with atof().  Here is a code snippet:

getline(cin, sRate);
record[i].rate = atof(sRate);

I need to convert the input sRate to an element of the struct employee that is in the array record[].  When I try to covert the input to a float using atof() I get the following error:

error: cannot convert 'std::string' to 'const char*' for argument'1' to double atof(const char*)

I am at a loss, so any help is greatly appreciated.  I can post more code if needed.  For reference here are my includes:

#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
#include <stdlib.h>

Thank you very much for your help,
Question by:bnblazer
LVL 20

Accepted Solution

ikework earned 2000 total points
ID: 16402842
record[i].rate = atof(sRate.c_str());

good luck :)

Author Comment

ID: 16403095
Ah yes - thank you!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

580 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