(if you are using windows, specifically 7)
You might want to check your path variable, search environment in your start menu's search bar, then click on "edit the system environment variables".
On the pop up click on environment variables go to the system variables section of the new popup, and look for path. click edit and copy the entire thing into a txt (it's long).
What you are looking at is a bunch of different paths that are searched first when trying to find dlls and such. You'll want to check if one of the paths is pointing to a compiler you no longer use. Then you'll want to check if your current compiler is mentioned.
If your compiler isn't mentioned, add it's bin folder to the variable and be sure to follow it with a semicolon. Make sure not to mess up any paths, and also save the path that you first copied down just in case. Copy all this back into the edit bar and submit it.
e.g. old path is
C:\Windows\System32
so add your compiler like this;
C:\Windows\System32;C:\mingw64\bin // bin should contain g++ and such
Hopefully, your program now compiles. I had this problem a few weeks ago and this method worked for me. if it doesn't work change the path variable back to what it was, and I apologize.