A
A
Andrey PINEAPPLE2014-03-26 15:26:00
C++ / C#
Andrey PINEAPPLE, 2014-03-26 15:26:00

How does the cin.peek function work?

while (!(cin >> b) || (cin.peek() != '\n') || (b <= 0))
                    {
                        cin.clear();
                        while (cin.get() != '\n');
                        cout << "Error enter!\n";
                        cout << "to begin again, press any key...\n";
                    }

Here is the code where it is applied. Also interested in the cin.clear() function.
PS. human language pls)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
evnuh, 2014-03-26
@evnuh

Which robot do you propose to explain?
And in the case - do you have a refman banned chtoli?
Looks at the next character without moving the cursor so-and-so.

1
1001001 111, 2014-03-26
@IgorO2

Have you tried searching on the site msdn.microsoft.com ?

A
Andrey PINEAPPLE, 2014-03-26
@AndreyHudz90

Could you describe this algorithm (code) point by point, what happens behind what.

while (!(cin >> b) || (cin.peek() != '\n') || (b <= 0))
                    {
                        cin.clear();
                        while (cin.get() != '\n');
                        cout << "Error enter!\n";
                        cout << "to begin again, press any key...\n";
                    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question