Home >Backend Development >C++ >How to Resolve the `max` Macro Collision Between Windows.h and the Standard Library?
Min and Max Macro Collision Between Windows.h and Std
When dealing with input validation in C , one may encounter a conflict between the max macro defined in Windows.h and the max function in the standard library. This can arise when attempting to clear the input stream error flag using the ignore function.
To resolve this issue, consider using the following approach:
#define NOMINMAX #include <Windows.h> #include <iostream> void Foo() { int delay = 0; do { if(cin.fail()) { cin.clear(); cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); } cout << "Enter number of seconds between submissions: "; } while(!(cin >> delay) || delay == 0); }
The NOMINMAX macro suppresses the min and max definitions in Windows.h, allowing the program to use the max function from the standard library without conflict. This approach eliminates the need to manually undefine the max macro and redefine it later.
The above is the detailed content of How to Resolve the `max` Macro Collision Between Windows.h and the Standard Library?. For more information, please follow other related articles on the PHP Chinese website!