// 编译环境: 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;
}
C++中数字和字符串类型的转换
最新推荐文章于 2023-11-30 21:55:28 发布
本文介绍如何使用C++进行字符串与整数之间的相互转换,包括如何将字符串转换为不同进制的整数。
1011

被折叠的 条评论
为什么被折叠?



