这个ostrstream的构造函数是什么意思?

紫色动力 2011-09-21 10:13:33
有个问题请教个位:

下面代码的第二行是构造了一个ostrstream对象吗?意思是ostr与text数组绑定,最大输出80个CHAR吗?谢谢!

char text[80];
ostrstream ostr(text,80);
...全文
110 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gfy5216 2011-09-23
  • 打赏
  • 举报
回复
初始化text数组,里面的80个元素都是null或者是随机的,不建议次初始化方式
ljhhh0123 2011-09-21
  • 打赏
  • 举报
回复
Quote=引用楼主 purplepower 的回复:]
有个问题请教个位:

下面代码的第二行是构造了一个ostrstream对象吗?意思是ostr与text数组绑定,最大输出80个CHAR吗?谢谢!

char text[80];
ostrstream ostr(text,80);
[/Quote]
这种写法吗?是ostringstream吧。而且构造函数也不是那样的。原型出自2003c++standard如下:
namespace std {
template <class charT, class traits = char_traits<charT>,
class Allocator = allocator<charT> >
class basic_stringstream
: public basic_iostream<charT,traits> {
public:
// Types
typedef charT
char_type;
typedef typename traits::int_type int_type;
typedef typename traits::pos_type pos_type;
typedef typename traits::off_type off_type;
typedef traits
traits_type;
// constructors/destructors
explicit basic_stringstream(
ios_base::openmode which = ios_base::out|ios_base::in);
explicit basic_stringstream(
const basic_string<charT,traits,Allocator>& str,
ios_base::openmode which = ios_base::out|ios_base::in);
basic_stringbuf<charT,traits,Allocator>* rdbuf() const;
basic_string<charT,traits,Allocator> str() const;
void str(const basic_string<charT,traits,Allocator>& str);
private:
// basic_stringbuf<charT, traits> sb;
exposition only
};
}

第2个参数是打开模式吧。
样例请参考《C++程序设计语言》特别版21.5.3章(563页)。
紫色动力 2011-09-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 taodm 的回复:]

最好自己亲自查手册。
最好不要用这个接口,如果它的功能真如你猜。
[/Quote]
这个函数大概意思把输入转化为字符串。不知道现在都用什么方法做,能给个例子吗?谢谢!
taodm 2011-09-21
  • 打赏
  • 举报
回复
最好自己亲自查手册。
最好不要用这个接口,如果它的功能真如你猜。

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧