problems with atof

Posted on 2006-04-07
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

    record[i].rate = atof(sRate.c_str());

    good luck :)
    LVL 1

    Author Comment

    Ah yes - thank you!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Some Windows API functions expect you to provide a pointer to a CALLBACK function that the system will need to call as part of the operation.  Such API functions as SetTimer, timeSetEvent, CreateThread, EnumWindows, LineDDA, even window message hand…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now