Double check :
1) Extension of your file - did you save your file as .cpp or .c? .cpp is the extension that is proper for you
2) If you have pre-installed compiler - Have you installed the proper version of Code::Blocks with pre-installed compiler. The link on code::blocks website should be called codeblocks-16.01mingw-setup.exe
If by any chance you installed wrong code::blocks then please:
a) UNINSTALL current code::blocks
b) install again using below link (windows):
with the preinstalled compiler!
3) Fix by one of the users (windows):
When I open my app-library in Win10 I have to choose which CodeBlock-image to open. At first I opened the one called only 'Code Blocks', and it did not compile.
But now finaly I opened the 'Code Blocks (Launcher)', and it works.
4)
You should go to Settings -> Compiler -> Toolchain Executables tab, and there you can find compiler settings.
Try to click on "auto detect" button, it should find it automatically.
Mine path is set to C:\Program Files (x86)\CodeBlocks\MinGW
5) MAC or Windows
I've been informed that some users must create a project. They cannot use single file like I did.
How to create project:
File (upper left corner of code::blocks) -> New -> Project...
Choose: Console application
Click on 'Next'
Choose: C++
Name project whatever you want so put in Project Title: "sample program"
Click 'Finish'
Now it should be fine :)
BTW console is white (not black) in MAC.
6) "there is no such file or directory" - Check your folder NAME
You shouldn't use special characters and you shouldn't use spaces especially on MAC.
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
I) error "C++ requires a type specifier for all declarations"
Solution: some IDE requires you to add 'int' before main and return 0 at the end, so your main project code should look like this:
#include <iostream> using namespace std; int main() { return 0; }
main is a function (covered in future lessons), almost every function is required to start with the type that is later returned. Do not worry about it right now. Just think about it that it has to be there. I will explain it ten thousands times better in future.
II) Console doesn't appear or instantly dissapears after compilation - add getchar(); command that ceases the program and wait for any char (character) from you before closing the console.
#include <iostream> #include <stdio.h> using namespace std; int main() { getchar(); return 0; }
You might need to include stdio.h at the top of your program to cause getchar(); command to execute. Why? because getchar is inside stdio.h - some IDEs includes stdio.h by default and there is no need to include it.
----------------------------------------------------------------------------------------------------------
If you have not found your solution here then please create a discussion or contact me directly describing your problem. I'm always here to support you!