2

I'm doing this little program in C++ but in codeblocks appears the following error: error:

'atod' was not declared in this scope

What I'm missing in this code? Thank you.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <fstream>
#include <math.h>
#include <iostream>

using namespace std;


class birth{
};


int main (void){

    int pass=1;
    string date, boy, aux1, aux2, aux4;
    double f;

    while(pass=! 0){
        cout<<"Enter the name of the birthday boy"<<endl;
        cin>>boy;
        cout<<"Enter the date of birth" <<endl;
        cin>>date;
        aux1= aux1.substr(5,10);
        f= atod(aux1);
        f=2012-f;
        cout<< "The birthday boy "<<boy<<"who born"<<date<<"now have"<<f<<"years"<<endl


        cout<<"Do you want to enter more birthdays?"<<endl;
        cout<<"1.- YES"<<endl;
        cout<<"2.- NO"<<endl;
        cin>>pass;
    }

    system ("pause");
    return 0;
};

EDIT: The problem is in this line:

 f= atod(aux1);
4

2 回答 2

3

使用该atof功能。它在stdlib.h。您需要将 a 传递const char*给它,而不是 a std::string

f = atof(aux1.c_str());
于 2012-09-24T02:14:38.463 回答
1

没有任何像 atod
使用_atold()or的功能atof(),这些在math.h&stdlib.h

于 2012-09-24T02:18:50.113 回答