当前位置:网站首页>Usage of stringstream
Usage of stringstream
2022-04-22 09:41:00 【I can't learn. I don't want to learn】
1. use stringstream To split the specified character string , The code is as follows :
// use stringstream To split the specified character string
#include <iostream>
#include <sstream>
#include <vector>
#include<queue>
#include<string>
using namespace std;
int main() {
string str = "1,2,3,4,5";
stringstream ss(str);
string item;
queue<string> q;
cout << str << endl;
while(getline(ss, item, ','))
cout << item << ' ';
return 0;
}
Running results :

2. String splicing , The code is as follows :
//stringstream For string splicing
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
#include<sstream>
int main()
{
stringstream sstream;
// Put multiple strings into sstream in
sstream << "first" << " " << "second";
sstream << " third times";
cout << " Output string : " << sstream.str() << endl;
// Empty sstream
sstream.str("");
sstream << "one more time";
cout << " After emptying the string , Output is : " << sstream.str() << endl;
return 0;
}
Running results :

3. Format numeric type data as a string , The code is as follows :
//stringstream Format numeric type data as a string
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
#include<sstream>
int main()
{
int a = 865;
string sa;
// Convert an integer variable to a string , Store in string The class object
stringstream s;
s << a;
s >> sa;
string strValue1;
strValue1 = s.str();
cout << strValue1 << endl;
// take stringstream Bottom management string Object set to "", Otherwise, when converting multiple times , Will accumulate all the results at the bottom string In the object
s.str("");
s.clear();// Empty s, If you don't empty it, the conversion will fail
double d = 12.34;
s << d;
s >> sa;
string strValue2;
// This method will manage the whole string Object returns , Not read / Effect of write pointer
strValue2 = s.str();// str() Method : return stringsteam In the management of string type
cout << strValue2 << endl;
return 0;
}
Running results :

版权声明
本文为[I can't learn. I don't want to learn]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220932126190.html
边栏推荐
- FUTR3D:一个统一的传感器融合3D检测框架
- leapftp:425 failed to establish connection解决方法
- Nacos
- L3-005 垃圾箱分布 (30 分)(dijkstar
- L3-003 social cluster (30 points) (concurrent search)
- L2-030 冰岛人 (25 分) (最近公共祖先 思维
- Implementation and analysis of watchablestore in etcd
- 杰理之复位IO维持电平使用说明【篇】
- 超越 iTerm!号称下一代 Terminal 终端神器,用完爱不释手!
- etcd Watch 异常场景
猜你喜欢

Simple operation of QT axobject Library

QT布局管理复习

辐射度量学基本概念

Heap overflow of kernel PWN basic tutorial

【C语言进阶10——字符和字符串函数及其模拟实现(1)】

Cloud native enthusiast weekly: looking for open source alternatives to netlify

在销量压力下,国产手机开始降价了,但还没有放下最后的面子

经典场效应管如何快速关断技巧-KIA MOS管

深度解析MOS管的GS波形分析-KIA MOS管

GS waveform analysis of depth resolved MOS transistor Kia MOS transistor
随机推荐
Transform based deep learning target detection (Detr model)
[age appropriate friends of interesting programming questions] (detailed explanation of the original title of leetcode)
The VirtualBox virtual machine uses virtio net to run dpdk + VPP and cannot receive VLAN messages
QT AxObject库的简单操作
L2-033 简单计算器 (25 分)
深度解析MOS管的GS波形分析-KIA MOS管
获取浏览器网址 地址
一文学会text-justify,orientation,combine文本属性
云原生爱好者周刊:寻找 Netlify 开源替代品
基于MOSFET控制的大范围连续可调(0~45V) 的小功率稳压电源设计实例
mysql主备配置 二进制日志问题
Input a string of characters randomly from the keyboard, count and output the times of each character (number, uppercase letter, lowercase letter, punctuation, etc.) in the string. It is realized with
L3-003 social cluster (30 points) (concurrent search)
leapftp:425 failed to establish connection解决方法
getimagesize()函数获取图片宽高取反
Aardio - 【库】webp图片转换
server 2019服务器可用内存是实际内存的一半
tensorflow实验四----波士顿房价预测
深度优先搜索(一):二叉树的中序遍历(力扣)
Online yaml to properties tool