本文共 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/