Break statement not within loop or switch

I know it must be something really stupid, but I can't figure it out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
while (!(cin >> onFeat));
{
        cin.clear();
        char ch;
        cin.get(ch);
        if (ch == 'Q' || ch == 'q')
        {
            while (cin.get() != '\n')
                continue;
            break;
        }
        std::cout << "\nWrong data. Please, try again: ";
        while (cin.get() != '\n')
            continue;
}
What are you trying to do...?
use cin.getchar() instead of cin.get()...
I'm still learning. This is part of the code of an exercise of a book. I don't know cin.getchar() yet. Do you spot any error with cin.get()?
The problem is that the first loop ends on line 1 because you put a semicolon at the end of the line.

@HiteshVaghani1
What is the difference between cin.getchar() and cin.get()?

Oh my god. I knew it had to be something really stupid. And indeed it is.

Thank you very much for all your help.
@Peter87
Actually there is not difference between cin.get() and cin.getchar() in working purpose.
For cin.get() we have to include <iostream> and for getchar() we have to include <cstdio>.
here break statement is never reached because of the continue statement used just before the break statement
Last edited on
Topic archived. No new replies allowed.