我需要在此范围内声明什么?

时间:2012-09-24 02:11:24

标签: c++

我正在使用C ++编写这个小程序,但在代码块中出现以下错误:错误:

  

'atod'未在此范围内宣布

我在这段代码中缺少什么?谢谢。

#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;
};

编辑:问题出在这一行:

 f= atod(aux1);

2 个答案:

答案 0 :(得分:3)

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

f = atof(aux1.c_str());

答案 1 :(得分:1)

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

相关问题