在C++有两种字符串流,一种在中定义,
另一种在strstream中定义。
它们实现的东西基本一样。

strstream里包含
class strstreambuf;
class istrstream;
class ostrstream;
class strstream;
它们是基于C类型字符串char*编写的

中包含
class istringstream;
class ostringstream;
class stringbuf;
class stringstream;
class …….
它们是基于std::string编写的

因此ostrstream::str()返回的是char*类型的字符串
而ostringstream::str()返回的是std::string类型的字符串

在使用的时候要注意到二者的区别,一般情况下推荐使用std::string类型的字符串
当然如果为了保持和C的兼容,使用strstream也是不错的选择。

相关日志

, ,

已经有4个回复

  1. 匿名 Says @ 08-04-22 12:55 am

    :em20:

    [回复]

  2. 匿名 Says @ 08-11-16 4:26 pm

    :em08: 刚刚决绝了一个相关的问题,谢谢!

    [回复]

  3. 匿名 Says @ 09-04-26 5:05 pm

    :em45: :em45: :em53: :em49: :em49: :em31: :em70: :em70: :em70: :em70: :em70:

    [回复]

  4. 匿名 Says @ 09-05-10 10:29 am

    :em40:

    [回复]

看完了要说点啥么?