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

#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

慕的地10843
浏览 239回答 2
2回答

慕森卡

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

MYYA

错误说atoi没有被声明,man atoi发现,包含atoi的头文件是stdlib.h,所以你只需要#include <stdlib.h>就可以了[root@localhost ~]# man atoiATOI(3) Linux Programmer’s Manual ATOI(3)NAMEatoi, atol, atoll, atoq - convert a string to an integerSYNOPSIS#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);DESCRIPTIONThe atoi() function converts the initial portion of the string pointed to by nptr to int. The behaviour is the same as.......
打开App,查看更多内容
随时随地看视频慕课网APP