zoukankan      html  css  js  c++  java
  • 2016.5.21——atoi()函数的测试

    对函数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型

  • 相关阅读:
    Smarty数学运算
    双引号里值的嵌入
    Smarty属性
    Smarty函数
    Smarty注释代码
    数据结构实验2——链表
    数据结构实验1——顺序表
    hdu 5459 Jesus Is Here
    hdu 5455 Fang Fang
    2018 多校6 hdu 6362 6370 6373
  • 原文地址:https://www.cnblogs.com/zhuzhu2016/p/5516477.html
Copyright © 2011-2022 走看看