对函数atoi()函数的测试:
atoi()函数将字符串型转换为整型
代码:
#include "stdafx.h"
#include "iostream"
#include "vector"
//#include <stdlib.h>
using namespace std; int _tmain(int argc, _TCHAR* argv[])
{
char str[] = { "" }; //这里不能定义成string型,出错:error C2664: “int atoi(const char *)”: 无法将参数 1 从“std::string [1]”转换为“const char *”
int m = ;
m = atoi(str)*;
//n = m * 2;
cout << m << endl;
system("pause");
return ;
}
注意定义字符串型时不能定义成string,而要定义为char型。否则出错:error C2664: “int atoi(const char *)”: 无法将参数 1 从“std::string [1]”转换为“const char *”
L9char str[] = { "12" }; 不能写成这样char str[] = { "12","45" },出错: error C2078: 初始值设定项太多
碎碎念:
字符串是双引号"",大括号{}!!!!,python中是单引号'',中括号[]
注意各种类型,经查提示我无法从XXX型转化为yyy型