首页 > 其他 > 详细

2016.5.21——atoi()函数的测试

时间:2016-05-22 12:04:46      阅读:290      评论:0      收藏:0      [点我收藏+]

对函数atoi()函数的测试:

  atoi()函数将字符串型转换为整型

  代码:

 1 #include "stdafx.h"
 2 #include "iostream"
 3 #include "vector"
 4 //#include <stdlib.h> 
 5 using namespace std;
 6 
 7 int _tmain(int argc, _TCHAR* argv[])
 8 {
 9     char str[] = { "12" };    //这里不能定义成string型,出错:error C2664: “int atoi(const char *)”: 无法将参数 1 从“std::string [1]”转换为“const char *”
10     int m = 0;
11     m = atoi(str)*3;
12     //n = m * 2;
13     cout << m << endl;
14     system("pause");
15     return 0;
16 }

  注意定义字符串型时不能定义成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型

2016.5.21——atoi()函数的测试

原文:http://www.cnblogs.com/zhuzhu2016/p/5516477.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!