为了账号安全,请及时绑定邮箱和手机立即绑定

atoi不是把char*转换为int的函数吗?难道不能用吗?

atoi不是把char*转换为int的函数吗?难道不能用吗?

C++
慕的地10843 2023-03-04 18:14:02
#include <iostream>#include <string>using namespace std ;int main ( ){string str = "123456" ;int num ;num = atoi (str.c_str( )) ;}linux下g++调试,报错:test.cpp: In function ‘int main()’:test.cpp:9: error: ‘atoi’ was not declared in this scope
查看完整描述

2 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

错误的意思,你没有申明atoi这个函数。atoi的头文件是 #include <stdlib.h> 
int main()结束要加上 return 0;

查看完整回答
反对 回复 2023-03-08
?
MYYA

TA贡献1868条经验 获得超4个赞

错误说atoi没有被声明,man atoi发现,包含atoi的头文件是stdlib.h,所以你只需要#include <stdlib.h>就可以了
[root@localhost ~]# man atoi
ATOI(3) Linux Programmer’s Manual ATOI(3)

NAME
atoi, atol, atoll, atoq - convert a string to an integer

SYNOPSIS
#include <stdlib.h>

int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);
long long atoq(const char *nptr);

DESCRIPTION
The atoi() function converts the initial portion of the string pointed to by nptr to int. The behaviour is the same as.......

查看完整回答
反对 回复 2023-03-08
  • 2 回答
  • 0 关注
  • 238 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号