basic_ios::tie
Ensures that one stream is processed before another stream.
basic_ostream<Elem, Traits> *tie( ) const;
basic_ostream<Elem, Traits> *tie(
basic_ostream<Elem, Traits> *_Str
);
매개 변수
- _Str
스트림입니다.
반환 값
The first member function returns the stored tie pointer. The second member function stores _Str in the tie pointer and returns its previous stored value.
설명
tie causes two streams to be synchronized, such that, operations on one stream occur after operations on the other stream are complete.
예제
In this example, by tying cin to cout, it is guaranteed that the "Enter a number:" string will go to the console before the number itself is extracted from cin. This eliminates the possibility that the "Enter a number:" string is still sitting in the buffer when the number is read, so that we are certain that the user actually has some prompt to respond to. By default, cin and cout are tied.
#include <ios>
#include <iostream>
int main( )
{
using namespace std;
int i;
cin.tie( &cout );
cout << "Enter a number:";
cin >> i;
}
요구 사항
Header: <ios>
네임스페이스: std