basic_streambuf::pubsync
basic_streambuf::pubsync
To synchronize the
streambuf object with its input/output.
int pubsync();
The function
pubsync() will attempt to synchronize the
streambuf input and output.
Returns zero if successful or
EOF if not via
sync().
#include <iostream>
struct address {
int number;
char street[40];
}addbook;
int main()
{
using namespace std;
cout << "Enter your street number: ";
cin >> addbook.number;
cin.rdbuf()->pubsync(); // buffer flush
cout << "Enter your street name: ";
cin.get(addbook.street, 40);
cout << "Your address is: "
<< addbook.number << " " << addbook.street;
return 0;
}
Result:
Enter your street number: 2201
Enter your street name: Donley Drive
Your address is: 2201 Donley Drive