cant see anything wrong with code you posted. Ill assume its just a snippet and you have a main() somewhere.
The error you are getting is usually associated with trying to compile a console program as a windows program.
Check your settings and be sure you are compiling for the right subsystem.