zoukankan      html  css  js  c++  java
  • 几种常见的库函数

    string s = to_string(num);/*
              std::string to_string(int value); (1) (C++11起)
              std::string to_string(long value); (2) (C++11起)
              std::string to_string(long long value); (3) (C++11起)
              std::string to_string(unsigned value); (4) (C++11起)
              std::string to_string(unsigned long value); (5) (C++11起)
              std::string to_string(unsigned long long value); (6) (C++11起)
              std::string to_string(float value); (7) (C++11起)
              std::string to_string(double value); (8) (C++11起)
              std::string to_string(long double value); (9) (C++11起)
              */      

    今天使用substring()函数,对于参数理解不是很好,在网上看也有好多错的,自己测试了一遍,记录下来

    substring(int beginIndex,int endIndex)中第一个参数是开始位置,第二个参数是结束位置,

    String s="abcdefg";
    System.out.println(s.substring(2,4));

    结果:cd

    如果只给一个参数,是从参数位置开始,一直到结束

    String s="abcdefg";
    System.out.println(s.substring(2));

    结果:cdefg

    注意:下标从零开始,包括前面的,不包括后面的,也可以看成是下标从一开始,不包括开始,包括结束。

    /*******

    vs环境下:
    stoi函数默认要求输入的参数字符串是符合int范围的[-2147483648, 2147483647],否则会runtime error。
    atoi函数则不做范围检查,若超过int范围,则显示-2147483648(溢出下界)或者2147483647(溢出上界)。
    
    
    stoi头文件:<string>,c++函数
    atoi头文件:<cstdlib>,c函数
    *******/
  • 相关阅读:
    计蒜客 移除数组中的重复元素 (双指针扫描)
    计蒜客 寻找插入位置 (二分查找)
    poj 1007 DNA Sorting
    全排列函数 nyoj 366(next_permutation()函数)
    nyoj 202 红黑树
    nyoj 92 图像有用区域
    nyoj 82 迷宫寻宝(一)
    nyoj 58 最少步数
    nyoj 43 24 Point game
    nyoj 42 一笔画问题
  • 原文地址:https://www.cnblogs.com/binanry/p/9623000.html
Copyright © 2011-2022 走看看