Windows.h and ofstream conflict

Hi everybody!
I have a problem in this test code. The compiler gives me "expected primary expression before <<" when i try to print on file. But if I comment #include <Windows.h> everything is correct (I comment the Sleep() function too or it says me Sleep() is undefined or undeclared).
Do ofstream and windows.h conflict?

P.S. If i declare and use an ifstream variable, it doesn't give me problems

Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <fstream>
#include <Windows.h>
using namespace std;

main(){
    ofstream OUT("output.txt");
    for(int i=10;i>0;i--){
    	cout<<"	 \r";
    	cout<<i;
    	Sleep(1000);
    	cout<<"\r";
    }
    OUT<<"Test";
    OUT.close();
}
1. main should be declared as int main()
2. OUT seems to be reserved by Windows. Use a different symbol.
3. Don't call close() on the fstream.
Thank you!! Stupid me...I solved using another name instead OUT!!!
OUT is a macro .You can use #undef to get rid of it after including windows.h if you insist of using OUT :)
Last edited on
i didn't know it was possible doing it!! yeah, i prefer to use #undef instead of overwrite OUT in all the files of my project!! Thank you very much!!
Topic archived. No new replies allowed.