try块里的gets()函数,error:在此作用域未声明解决方案

来源:互联网 发布:淘宝bape复刻哪家好 编辑:程序博客网 时间:2024/06/06 07:42
try块里的gets()函数,error:在此作用域未声明
C/C++ code
#include<iostream>using namespace std;int main(){ char a[10]; double x; try {   int flag=0;   gets(a);   for(int i=0;a[i]!='\0';i++)    if(!(a[i]>='0'&&a[i]<='9'||a[i]=='.')){cout<<"输入为非数字"<<endl;flag=1;break;}   if(flag==0)   {    throw 0;   } } catch(int) {  cout<<"输入为数字"<<endl;    x=atof(a);//该函数把字符串(即数组中的全部元素)转换成数字    cout<<x<<endl; } return 0;}

error:gets()在此作用域未声明,atof()在此作用域未声明

------解决方案--------------------------------------------------------
貌似是没有包含头文件。
------解决方案--------------------------------------------------------
#include <cstdio>
#include <cstdlib>
原创粉丝点击