/// read() + ignore()
#include <iostream> /// cin, cout
using namespace std;
void read()
{
char buf[80] {};
cin.readsome(buf, 3);
if (cin)
{
cout << "cin.readsome() successfully read "
<< cin.gcount() << " characters: ";
cout << buf << endl;
cout << "next char: " << (char) cin.peek()
<< endl;
/// discard the character
cin.ignore();
}
else
cout << "cin.readsome() was unsuccessful" << endl;
}
int main()
{
for (int i = 0; i < 3; i++)
read();
}
Ly8vIHJlYWQoKSArIGlnbm9yZSgpCgojaW5jbHVkZSA8aW9zdHJlYW0+ICAgICAgICAgLy8vIGNpbiwgY291dAoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgp2b2lkIHJlYWQoKQp7CiAgICBjaGFyIGJ1Zls4MF0ge307CgogICAgY2luLnJlYWRzb21lKGJ1ZiwgMyk7CgogICAgaWYgKGNpbikKICAgIHsKICAgICAgICBjb3V0IDw8ICJjaW4ucmVhZHNvbWUoKSBzdWNjZXNzZnVsbHkgcmVhZCAiCiAgICAgICAgICAgICA8PCBjaW4uZ2NvdW50KCkgPDwgIiBjaGFyYWN0ZXJzOiAiOwoKICAgICAgICBjb3V0IDw8IGJ1ZiA8PCBlbmRsOwoKICAgICAgICBjb3V0IDw8ICJuZXh0IGNoYXI6ICIgPDwgKGNoYXIpIGNpbi5wZWVrKCkKICAgICAgICAgICAgIDw8IGVuZGw7CiAgICAgICAgICAgICAKICAgICAgICAvLy8gZGlzY2FyZCB0aGUgY2hhcmFjdGVyCiAgICAgICAgY2luLmlnbm9yZSgpOwogICAgfQogICAgZWxzZQogICAgICAgIGNvdXQgPDwgImNpbi5yZWFkc29tZSgpIHdhcyB1bnN1Y2Nlc3NmdWwiIDw8IGVuZGw7Cn0KCgppbnQgbWFpbigpCnsKCWZvciAoaW50IGkgPSAwOyBpIDwgMzsgaSsrKQogICAgICAgcmVhZCgpOwp9