std::ostrstream::ostrstream
STD::发情流::发情流
ostrstream( | (1) | |
---|---|---|
ostrstream(char* s, int n, std::ios_base::openmode mode = std::ios_base::out | (2) | |
构造新的输出strstream及其基础std::strstreambuf
...
1%29默认值-构造基础std::strstreambuf
,它创建一个动态增长的缓冲区,并使用strStrebuf成员的地址初始化基类。
2%29使用基础的地址初始化基类。std::strstreambuf
成员,它以两种可能的方式之一初始化,这两种方式都写入用户提供的固定大小数组:
A%29如果app
位未设置mode
,通过调用strstreambuf(s, n, s)
如果有少于n
数组中的第一个元素被s
b%29如果app
位mode
,通过调用strstreambuf(s, n, s +
std::strlen
(s))
如果有少于n
数组中的第一个元素被s
或者如果数组不包含有效的以空结尾的字符序列.
参数
s | - | char array to use as the output buffer |
---|---|---|
n | - | size of the array to be used as the output buffer |
mode | - | specifies stream open mode. It is a bitmask type, the following constants are defined (although only app is used): Constant Explanation app seek to the end of stream before each write binary open in binary mode in open for reading out open for writing trunc discard the contents of the stream when opening ate seek to the end of stream immediately after open |
Constant | Explanation | |
app | seek to the end of stream before each write | |
binary | open in binary mode | |
in | open for reading | |
out | open for writing | |
trunc | discard the contents of the stream when opening | |
ate | seek to the end of stream immediately after open |
例
二次
#include <iostream>
#include <strstream>
int main()
{
std::ostrstream s1; // dynamic buffer
s1 << 1 << ' ' << 3.14 << " example\n" << std::ends;
std::cout << s1.str(
s1.freeze(false
char arr[15] = "Hello";
std::ostrstream s2(arr, sizeof arr, std::ios_base::app
s2 << ", world!" << std::ends;
std::cout << s2.str() << '\n';
std::cout << arr << '\n'; // streams use the provided arrays
}
二次
产出:
二次
1 3.14 example
Hello, world!
Hello, world!
二次
另见
(constructor) | constructs a strstreambuf object (public member function of std::strstreambuf) |
---|---|
(constructor) | constructs an strstream, optionally allocating the buffer (public member function of std::istrstream) |
(constructor) | constructs an strstream, optionally allocating the buffer (public member function of std::strstream) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。