Home > Backend Development > C++ > How to Resolve Max Macro Collisions Between Windows.h and std::max?

How to Resolve Max Macro Collisions Between Windows.h and std::max?

Patricia Arquette
Release: 2024-11-10 13:38:02
Original
433 people have browsed it

How to Resolve Max Macro Collisions Between Windows.h and std::max?

Dealing with Max Macro Collision in Windows.h and Std

Windows.h includes WinDef.h, which defines the min and max macros. This can conflict with the max macro defined in std, leading to compilation errors.

To resolve this issue, you can use the following workaround:

#define NOMINMAX

#include <Windows.h>
#include <iostream>

using std::cin;
using std::cout;

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);
}
Copy after login

By defining the NOMINMAX macro, you suppress the min and max definitions in WinDef.h, allowing you to use the max macro from std without any conflicts.

The above is the detailed content of How to Resolve Max Macro Collisions Between Windows.h and std::max?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template