I'm writing a function that reads an IP address from input and generates its 32-byte values. If the input is correct, the whole thing can be done by this:

int a, b, c, d;
char buf;

If it's not, such as, or 1..2.3.4, I want to ignore the whole line and start with a new line. One solution I found is using a string to read the leave characters. Like:

if (!checkinput())
    string str;
    getline(cin, str);

I just hate to use a new variable. How can I do the job with istream's own functions?