zoukankan      html  css  js  c++  java
  • 字符串和整数之间的转换

    一、使用stringstream 类
    c++中的 <sstream>库定义了三种类:istringstream、ostringstream和stringstream,分别用来进行流的输入、输出和输入输出操作。

     

    二、c++中 stoi
    将 n 进制的字符串转化为十进制
    示例:
    stoi(str, 0, 2); //将字符串 str 从 0 位置开始到末尾的 2 进制转换为十进制


    三、atoi、atof、atol、itoa等
    C标准库<stdlib.h>提供了 atoi, atof, atol, atoll(C++11标准) 函数将字符串转换成int,double, long, long long 型。

    而非标准函数itoa、litoa()、ultoa()可以将int、long、unsigned long型整数转换为字符串类型。

  • 相关阅读:
    最小路径
    零钱兑换
    硬币
    三步问题
    区域和检索
    除数博弈
    URI和URL的辨别
    交叉编译OpenMP
    牛客挑战赛44D-数列的和
    CF1408H. Rainbow Triples
  • 原文地址:https://www.cnblogs.com/sunshine1218/p/14641609.html
Copyright © 2011-2022 走看看