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

Small BASIC
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.
280 questions
C++
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.
3,753 questions
0 comments No comments
{count} votes

Accepted answer
  1. WayneAKing 4,921 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 Answers by the question author, which helps users to know the answer solved the author's problem.