#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 回答
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.......
- 2 回答
- 0 关注
- 238 浏览
添加回答
举报
0/150
提交
取消
