zoukankan      html  css  js  c++  java
  • 第二十一章流 15sstream字符串输入输出流类 简单

    //第二十一章流 15sstream字符串输入输出流类
    /*#include <iostream>
    #include <sstream>
    #include <string>
    using namespace std;
    int main()
    {
    	ostringstream out;
    	//ostringstream 类从ostream类派生而来,因此ostringstream类对像有cout对像的特征
    	char *str = "hello world";
    	float num=314.57f;
    	out.precision(2);
    	out<<fixed;
    	cout<<num<<str<<endl;
    	string ch=out.str();
    	cout<<ch;
        return 0;
    }
    */
    #include <iostream>
    #include <sstream>
    #include <string>
    using namespace std;
    int main()
    {
    	//当然也可以将while(in>>ch)替换为while(in.get(ch)),这样,输出的结果就变为:
    	//Next morning I will stay at home
    	string str="Next morning I will stay at home.";
    	istringstream in(str);
    	string ch;
    	while(in>>ch)
    	{
    	    cout<<ch<<endl;
    	}
    	//总之 istringstream 对像和ostringsstrem对像可以使用ifstream类和ofstream类的方法来管理字符串对像的数据
        return 0;
    }
    

      

  • 相关阅读:
    小X的密码破译
    小X的加法难题
    足球联赛
    机器分配
    化装晚会
    Soundex编码
    迷之阶梯
    使用JMeter做压力测试
    SCOI 2010 序列操作
    动态求区间K大值(权值线段树)
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2709706.html
Copyright © 2011-2022 走看看