windows.h not getting along with the rest of the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

#include <iostream>
#include "windows.h"       <-- Including "windows.h" (or <windows.h>) causes the errors!
#include <limits>

using namespace std;	

void cls(HANDLE hConsole);  <-- I'm using the recommended method of clearing a DOS box per Microsoft (and Duoas, thanks!).


int main(){

	float InDeg = 0.0;		// Used for the numeric portion of the user input.
	char Scale_Type;		// We also have to know if the user means Celsius or Fahrenheit.

	do{
		cls(hConsole);
		cout << "Enter in the temperature that you want converted (i.e. '32 f'):\n";

		cin.clear();
		cin.ignore(numeric_limits<streamsize>::max(), '\n');   <-- Used to clear "cin" of garbage characters.  

		cin >> InDeg >> Scale_Type;			

The rest was deleted to keep things concise... 


So when I try to compile my project, I get the following warning and errors:

c:\...\main.cpp(51) : warning C4003: not enough actual parameters for macro 'max'
c:\...\main.cpp(51) : error C2589: '(' : illegal token on right side of '::'
c:\...\main.cpp(51) : error C2143: syntax error : missing ')' before '::'
c:\...\main.cpp(51) : error C2059: syntax error : ')'

(Because of me trimming my code to show the problem, the actual line number for these errors is now 21).

I included "cin.ignore(numeric_limits<streamsize>::max(), '\n');" because of getting errors that wouldn't clear in cin. It works as expected when used without the "cls" function.

If I don't include the function to clear the screen (cls) then everything works fine.

Using "Using namespace std;" or not (and in that case, prepending my cin, cout, etc with std::) makes no difference whatsoever.

Sure, I could use a system call, but I'd rather not get into bad habits this early on (I'll wait until my boss gives me a deadline :lol: ). For now, I'm learning this on my own just for my own edification, so there's no pressure on me to get it working right away.

Besides, I spend most of my time in linux, so I'd be much better off learning how to do things "The Right Way" rather than use OS specific shortcuts.

Is this a VC++ Express Edition issue? I've read where windows.h wasn't included with the free edition. Should I be using a different IDE/Compiler?


Thanks guys!



Windows declares lots of macros, one of them is 'max' which will replace 'max' in numeric_limits<streamsize>::max().
To remove that macro, add these lines after #including <windows.h>:
1
2
3
#ifdef max 
#undef max
#endif 
While you're at it, do the same for min. They're hangovers from a more primitive age.

1
2
3
#ifdef min
#undef min
#endif 
Those ideas both work, but the way that I think you ought to do it is #define NOMINMAX , as this is the define that the file checks to see whether it should define those macros in the first place.
Perfect! Thanks guys, that worked like a charm. :)
Topic archived. No new replies allowed.