C++中数字和字符串类型的转换


// 编译环境: VS2013,C++11

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cstring>

int _tmain(int argc, _TCHAR* argv[])
{



    string s = "1245";

    string  a = to_string(12345);//将整型转换为字符串
    //stoi(s,p,base) 参数s表示要转换的字符串,参数p是指向第一个非数字的指针,参数base是转换的基数10进制2进制等等,后面两个是默认参数
    int b = stoi(s);//将字符串转换为整型
    string c = "1011100";
    int  d = stoi(c,0,2);//二进制转换


    cin.get();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/cosmopolitanme/article/details/79939311
今日推荐