目录

sync

描述 (Description)

它用于同步输入缓冲区。

声明 (Declaration)

以下是std :: basic_istream :: sync的声明。

int sync();

参数 (Parameters)

没有

返回值 (Return Value)

如果函数失败,或者因为没有流缓冲区对象与流关联(rdbuf为null),或者因为对其pubsync成员的调用失败,它返回-1。否则,它返回零,表示成功。

异常 (Exceptions)

Basic guarantee - 如果抛出异常,则对象处于有效状态。

数据竞争 (Data races)

修改流对象。

例子 (Example)

在下面的示例中,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
↑回到顶部↑
WIKI教程 @2018