我需要在此范围内声明什么? 我在C++中做这个小程序,但是在CODBROCK中出现了以下错误:错误:
“atod”未在此作用域中声明 我在这段代码中遗漏了什么?多谢各位我需要在此范围内声明什么? 我在C++中做这个小程序,但是在CODBROCK中出现了以下错误:错误:,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{ };
#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;
};
使用
atof
功能。它在stdlib.h
中。您需要向它传递一个const char*
,而不是std::string
f = atof(aux1.c_str());
使用
atof
功能。它在stdlib.h
中。您需要向它传递一个const char*
,而不是std::string
f = atof(aux1.c_str());
没有任何类似atod的函数
使用
\u atold()
或atof()
,它们位于math.h
&stdlib.h
没有任何类似atod的函数使用
\u atold()
或atof()
,这些都在math.h
和stdlib.h
使用strtod
、stod
、stringstream或boost::lexical\u cast
实现。顺便说一句,您的循环条件pass=!0将永远循环。它不断地将pass
设置为非零(true)。您的意思可能是pass!=0
。一旦你有了这个权利,你需要看看你在循环结束时给用户的选择,问问自己你是否在测试正确的值。通常一个错误说“…没有在这个范围内声明”意味着你需要一个#include
语句。您需要找出定义atod()
函数(如果有的话)的标题。或者找到正确的函数名来执行所需操作。使用strtod
、stod
、stringstream或boost::lexical_cast
。顺便说一句,循环条件pass=!0将永远循环。它不断地将pass
设置为非零(true)。您的意思可能是pass!=0
。一旦你有了这个权利,你需要看看你在循环结束时给用户的选择,问问自己你是否在测试正确的值。通常一个错误说“…没有在这个范围内声明”意味着你需要一个#include
语句。您需要找出定义atod()
函数(如果有的话)的标题。或者找到正确的函数名来做你想做的。好吧,我这么做了,但是当程序请求我出生日期时,程序崩溃了。。你知道会是什么吗?是的,很可能是你试图从空字符串中拉出一个子字符串的那一部分。好的,我这样做了,但是当程序请求我出生日期时,程序崩溃了。。你知道可能是什么吗?是的,很可能是你试图从空字符串中拉出一个子字符串的那部分aux1
。