共用方式為


basic_ios::tie

確定資料流在另一個資料流之前處理作業。

basic_ostream<Elem, Traits> *tie( ) const;
basic_ostream<Elem, Traits> *tie( 
    basic_ostream<Elem, Traits> *_Str
);

參數

  • _Str
    資料流。

傳回值

第 10% 成員函式傳回儲存的 WITH TIES 指標。 第二 + 成成員函式在 WITH TIES 指標儲存 _Str 並傳回其最後儲存的值。

備註

tie 會導致兩個資料流同步,這樣一來,在資料流作業發生,在另一個資料流的作業完成之後。

範例

在此範例中,您可以繫結至 cout 的 cin,保證「輸入每個數字: ,在數字 cin 之前,擷取」字串將移至主控台。 這會排除這種可能性「輸入每個數字: 」字串緩衝區仍然座標,當數字讀取時,因此,我們確定使用者實際上有一些提示回應。 根據預設, cin 和 cout 繫結。

#include <ios>
#include <iostream>

int main( ) 
{
   using namespace std;
   int i;
   cin.tie( &cout );
   cout << "Enter a number:";
   cin >> i;
}

需求

標題: <ios>

命名空間: std

請參閱

參考

basic_ios 類別

iostream 程式設計

iostreams 慣例