Expected identifier with numeric_limits

Aug 22, 2014 at 4:21pm
I'm trying to perform a simple input operation, and check to make sure that whatever the user input is a valid input (is within data type bounds, is correct data type...). But when I get to ignoring the input, I keep getting an error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
unsigned short num;

while (true)
{
     std::cin >> num;

     if (std::cin.fail())
     {
          num = 1;
          std::cout << "Error" << std::endl;

          std::cin.clear();

          std::cin.ignore(std::numeric_limits<unsigned short>::max/*Error: expected an identifier*/(), '\n');
     }
}


I don't fully understand why this error is here. I'm writing things just as they are on the tutorial.
If someone could help me out, that would be much appreciated.
Aug 22, 2014 at 5:36pm
Microsoft had a bad day and defined lowercase min and max macros in their Windows.h header.
1
2
#undef min
#undef max 
Aug 22, 2014 at 6:19pm
Or:

#define NOMINMAX
Last edited on Aug 22, 2014 at 6:19pm
Aug 22, 2014 at 6:23pm
@xismn That's no good in header files as Windows.h will have already been included.
Last edited on Aug 22, 2014 at 6:23pm
Aug 22, 2014 at 6:50pm
1
2
3
4
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h> 
Aug 22, 2014 at 7:43pm
@Duoas
1
2
#include <Windows.h>
#include <YourHeader.h> 
What now?
Last edited on Aug 22, 2014 at 11:26pm
Aug 22, 2014 at 8:09pm
Works like a charm. Thanks guys :)
Topic archived. No new replies allowed.