博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ Primer Plus学习笔记 第十七章 内核格式化
阅读量:4126 次
发布时间:2019-05-25

本文共 1131 字,大约阅读时间需要 3 分钟。

sstream族提供与iosream相同的接口提供程序与string对象之间的I/O

读取string对象中的格式化信息和将格式化信息写入到string对象中称为内核格式化(。。。跟内核有毛关系啊)

string:sstream

char字符数组: strstream.h

 

sstream -> ostringstream string对象的输入流类

               -> wostringstream 宽字符的

str()终结修改缓冲区内容

#include 
// 来自sstream头#include
#include
int main(){ using namespace std;// 声明outstr对象 ostringstream outstr; string hdisk; cout << "What's the name of your hard disk? "; getline(cin, hdisk); int cap; cout << "What's its capacity in GB? "; cin >> cap;// 将string写入到outstr缓冲区中 outstr << "The hard disk " << hdisk << " has a capacity of " << cap << " gigabytes.\n";// 冻结! the end! string result = outstr.str();// 输出到终端 cout << result; return 0;

 

sstream -> istringstream 输出流,初始化的时候与相关的string对象做绑定 然后可以取出相关的字符串

#include 
#include
#include
int main(){ using namespace std; string lit = "It was a dark and stormy day, and " " the full moon glowed brilliantly. ";// 初始化的时候需要绑定相应的对象 istringstream instr(lit); string word;// 重载了operator>>() while(instr >> word) cout << word << endl; return 0;}

总结

感天动地  17章终于完结了

转载地址:http://tsepi.baihongyu.com/

你可能感兴趣的文章
浅谈Bash shell的几种运行模式和cron环境变量导致command not found
查看>>
Linux bash的快捷键 提高效率
查看>>
ubuntu 16.04 Titanxp 安装cuda10.0 cudnn7.6 环境
查看>>
git使用教程
查看>>
linux gcc编译环境变量和动态库路径问题浅析以及LD_LIBRARY_PATH和LIBRARY_PATH区别
查看>>
Ubuntu 16.04 编译安装opencv 3.4.6过程和 anaconda3/lib/libtiff.so.5: undefined reference to `ZSTD_freeCStre
查看>>
C++ 拷贝构造和赋值构造示例
查看>>
python numpy list 多维度数组保存和读取恢复
查看>>
对抗样本 FGSM 算法代码实现 Adversarial Examples Keras Tensorflow实现
查看>>
because cuDNN failed to initialize Tensorflow 显存分配。
查看>>
ByteArrayInputStream和ByteArrayOutputStream 避免创建临时文件
查看>>
SpringBoot Hadoop HDFS目录文件下载
查看>>
CFI and SFI
查看>>
fedora 8 安装 scilab
查看>>
fc 8 安装xen
查看>>
Linux 汇编语言开发指南
查看>>
马拉松(一)
查看>>
ES TCP客户端方式自动映射mapping写入异常
查看>>
ES自定义Analyzer扩展IK分词
查看>>
记录一次系统计算逻辑优化
查看>>