C++中int型与string型互相转换
来源:互联网 发布:徐州淘宝店铺装修 编辑:程序博客网 时间:2024/05/20 11:23
本以为这么多年C#经验,学个C++没多难,现在发现错了。C++真TM难。
今天遇到int转string绊了半天,方法很多,不知道为什么搞那么复杂,
我只挑最简单易懂的,管他效率不效率的。
int转string
int n = 0;
std::stringstream ss;
std::string str;
ss<<n;
ss>>str;
string转int
std::string str = "123";
int n = atoi(str.c_str());
#include "stdafx.h"
#include <string>
#include <sstream>
using namespace std;
void main()
{
// int 转 string
stringstream ss;
int n = 123;
string str;
ss<<n;
ss>>str;
// string 转 int
str = "456";
n = atoi(str.c_str());
}
今天遇到int转string绊了半天,方法很多,不知道为什么搞那么复杂,
我只挑最简单易懂的,管他效率不效率的。
int转string
int n = 0;
std::stringstream ss;
std::string str;
ss<<n;
ss>>str;
string转int
std::string str = "123";
int n = atoi(str.c_str());
#include "stdafx.h"
#include <string>
#include <sstream>
using namespace std;
void main()
{
// int 转 string
stringstream ss;
int n = 123;
string str;
ss<<n;
ss>>str;
// string 转 int
str = "456";
n = atoi(str.c_str());
}
0 0
- C++int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- C++中int型与string型互相转换
- String 与 int 互相转换
- C字符串和C++中string的区别 &&&&C++中int型与string型互相转换
- Java中int与String类型的互相转换
- 浅析 java中 Int 与 String 互相转换问题
- C# Enum与int,string互相转换
- C12_OC02-OC较C的不同
- 如何学习的进步的速度最快了?
- uva10719
- C13_OC03-面向对象
- 【Qt】Qpainter制作二维图
- C++中int型与string型互相转换
- [学习中的错误记录]
- C++动态申请数组和参数传递问题
- LeetCode Sqrt(x)
- VS2005的配置问题-mainifest 查看所需依赖项
- Codeforces 425B
- java File类的基本操作
- java--多线程实现两种方式
- javafx之CSS初探