C++: How to use cin.ignore() to ignore all possible characters in an input

Steph 61 Reputation points
2021-12-04T22:01:47.337+00:00

I'm making a silly little text-based "VN" in c++, and have run in to a small snag. I want to use while loops to catch errors, and have tried using cin.ignore(numeric_limits<streamsize>::max(), '\n') to only have the error message display ONCE. Otherwise, the error message will display for every letter that is an incorrect input. Can anyone help me with this? Thanks so much!154993-2021-12-04-2.png155007-2021-12-04.png

Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Developer technologies | Small BASIC
Developer technologies | Small BASIC
A programming language created by Microsoft that serves a stepping stone for beginners from block-based coding languages to more complex text-based languages.
0 comments No comments
{count} votes

Answer accepted by question author
  1. WayneAKing 4,931 Reputation points
    2021-12-05T03:15:23.633+00:00

    To eliminate the compile errors shown in your pic,
    add the following macro before the windows.h
    include statement:

    #define NOMINMAX
    #include <windows.h>
    
    • Wayne

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.