public member function
<sstream>

std::basic_stringstream::rdbuf

basic_stringbuf<char_type,traits_type,allocator_type>* rdbuf() const;
獲取流緩衝區
返回指向內部 basic_stringbuf 物件的指標。

請注意,這不一定與其當前“*關聯的流緩衝區*”(由繼承的 basic_ios::rdbuf 成員返回)相同。

引數



返回值

指向內部 basic_stringbuf 物件的指標。
char_typetraits_typeallocator_type 是成員型別,它們被定義為類模板引數的別名(請參閱 basic_stringstream 型別)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// stringstream::rdbuf
#include <string>       // std::string
#include <iostream>     // std::cout
#include <sstream>      // std::stringstream, std::stringbuf

int main () {
  std::stringstream ss;

  // using stringbuf directly:
  std::stringbuf *pbuf = ss.rdbuf();
  pbuf->sputn ("Example string",13);

  char buffer[80];
  pbuf->sgetn (buffer,80);

  std::cout << buffer;

  return 0;
}

Example string


資料競爭

訪問流物件。
併發訪問同一個流物件可能導致資料爭用。

異常安全

強保證:如果丟擲異常,流緩衝區將不會發生任何更改。

另見