There is no error in the code of the above program. You just need to add the path to the "mingw32 \ bin" folder to the PATH system variable. Or create a batch file in the project folder. For example, "D: \ tests \ env.cmd"
PUSHD SETLOCAL SET "_MINGW=D:\MinGW\i686-6.2.0-release-posix-dwarf-rt_v5-rev0\mingw32\" SET "PATH=%_MINGW%bin;%_MINGW%opt\bin;%PATH%" cmd.exe /K ENDLOCAL POPD
Just change the path to where you have Mingw. Run the batch file, and in the resulting window, type the command to compile. For example, your file with the code "D: \ tests \ test.cpp". Then:
D:\tests>c++ test.cpp -o test D:\tests>test.exe
If there are errors, then you just need to download the latest mingway. For example: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/5.3.0/threads-posix/sjlj/i686-5.3.0-release- posix-sjlj-rt_v4-rev0.7z
In the case of using any developer environment, I think this is just your case, you need to carefully check all the environment settings in the IDE options.