public member function
<istream> <iostream>

std::istream::istream

初始化 (1)
explicit istream (streambuf* sb);
初始化 (1)
explicit istream (streambuf* sb);
複製 (2)
istream& (const istream&) = delete;
移動 (3)
protected: istream& (istream&& x);
構造物件
構造一個 istream 物件。

(1) 初始化建構函式
透過呼叫繼承的成員 ios::init 並將 sb 作為引數,為基類的組成部分分配初始值。
(2) 複製建構函式 (已刪除)
已刪除:沒有複製建構函式。
(3) 移動建構函式 (受保護)
獲取 x 的內容,但不包括其關聯的 流緩衝區:它複製 xgcount 值,然後呼叫 ios::move 來轉移 xios 組成部分。xgcount 值將變為零,未被 *繫結*,並且其關聯的 流緩衝區 保持不變(呼叫後 x 的所有其他組成部分處於未指定但有效狀態)。

引數

sb
streambuf 物件的指標。
x
另一個 istream 物件。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// istream constructor
#include <iostream>     // std::ios, std::istream, std::cout
#include <fstream>      // std::filebuf

int main () {
  std::filebuf fb;
  if (fb.open ("test.txt",std::ios::in))
  {
    std::istream is(&fb);
    while (is)
      std::cout << char(is.get());
    fb.close();
  }
  return 0;
}

此示例程式碼使用一個 filebuf 物件(從 streambuf 派生)來開啟一個名為 test.txt 的檔案。該緩衝區作為引數傳遞給 istream 物件 is 的建構函式,將其與流關聯。然後,程式使用輸入流將其內容列印到 cout

istream 類的物件很少被直接構造。通常使用派生類(如標準的 ifstreamistringstream)。

資料競爭

sb 指向的物件可能被訪問和/或修改。

異常安全

如果丟擲異常,唯一的副作用可能來自對 sb 的訪問/修改。

另見