Cpp-standard-library-cpp-basic-ios-synch
提供:Dev Guides
C ++ basic_iosライブラリ-同期
説明
入力バッファを同期するために使用されます。
宣言
- 以下は、std
- basic_istream :: syncの宣言です。
int sync();
パラメーター
none
戻り値
ストリームバッファオブジェクトがストリームに関連付けられていない(rdbufがnull)か、pubsyncメンバーの呼び出しが失敗したために関数が失敗した場合、-1を返し、ゼロを返し、成功を示します。
例外
基本保証-例外がスローされた場合、オブジェクトは有効な状態です。
データの競合
ストリームオブジェクトを変更します。
例
- 以下のstd
- basic_istream :: syncの例。
#include <iostream>
int main () {
char first, second;
std::cout << "Please, enter a word: ";
first = std::cin.get();
std::cin.sync();
std::cout << "Please, enter another word: ";
second = std::cin.get();
std::cout << "The first word began by " << first << '\n';
std::cout << "The second word began by " << second << '\n';
return 0;
}
出力は次のようになります-
Please, enter a word: test
Please enter another word: text
The first word began by t
The second word began by t