Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4449484
  • 博文数量: 356
  • 博客积分: 10458
  • 博客等级: 上将
  • 技术积分: 4734
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-24 14:59
文章分类

全部博文(356)

文章存档

2020年(17)

2019年(9)

2018年(26)

2017年(5)

2016年(11)

2015年(20)

2014年(2)

2013年(17)

2012年(15)

2011年(4)

2010年(7)

2009年(14)

2008年(209)

分类: C/C++

2008-05-23 17:05:01

//awzzz@2002
//入门计划->使用(C++库)ostringstream输出(格式化)
//APO->using ostringstream.
//accidence project of using ostringstream.(c++ iostream library)

/*
  Reference:

  Description

  ostringstream class provides an interface to manipulate strings as if
  they were output streams.

  The objects of this class mantain internally a pointer to a stringbuf
  object that can be obtained/modified by calling member rdbuf. This
  streambuf-derived object stores a sequence of characters (string) that
  can be obtained/modified by calling member str.
*/


//使用(C++库)ostringstream输出(格式化)
//simple example

#include
#include
#include
using namespace std;

void test()
{
    //ostringstream oss;
    //oss.str("abc");
    ostringstream oss("abc");
   
    cout << oss.str() << endl;

    oss << 8 << endl;
    oss << 3.14 << endl;
    oss << " ok ." << endl;

    cout << oss.str() << endl;

    oss << 8 << " "
        << 3.14 << " "
        << " ok ." << endl;

    cout << oss.str() << endl;
}

int main(int argc, char* argv[])
{  
    test();
    return 0;
}
输出:
abc
8
3.14
 ok .
8
3.14
 ok .
8 3.14  ok .
Press any key to continue
阅读(8821) | 评论(0) | 转发(0) |
0

上一篇:c++格式化输入输出

下一篇:2道无聊的题

给主人留下些什么吧!~~