Create a sample program with Code::Blocks

If you’re new to Code::Blocks IDE and you’ve already downloaded and installed the program, it’s a good time to create your first program. We’ll  go over the steps to create a specific starter program using Code::Blocks and programming in C++. This is a great way to get familiar with the layout and workings of the software.

Add files to your project

Follow these steps to add files:

Edit your files

Syntax

In C++ there is no special syntax for streaming data input or output. Instead, these are combined as a library of functions. Iostream provides basic input and output services for C++ programs; it must be included for your program to function properly. This is why we must include the #include< Iostream> line in our program.

We also must include the #include to the program in C++ . Be sure the statements you wish to print in the console are between “” quotation marks. For example:

cout << “Hello there!….or should I say NAMASTE “<

Be sure to use correct beginning and ending statements with each line of code. For basic C++ syntax please see this link.

Input the following code into your project (see the image above for comparison):

#include #include //wxDev-C++ users may need this header file here to allow calls to system commands

using namespace std;

int main() { cout << “Hello there!….or should I say NAMASTE “<

}

Then save your work.

Compiling

After you complete the writing and editing of your program, you must compile the file. To do this, first go to the Build menu and select Compile Current File (or Ctrl+Shift+F9).

Next, test your project. From the Build pull-down menu, click Build and Run . This step will build an executable file for you. A project build takes the compiled versions of your source files and combines them into one single program. Your program output will now be displayed. You will see all of the text you wrote in between the quotes displayed as program output.

If an error is displayed, check the syntax of your code and check for missing pieces, or unintentional errors.

Although this is a very simple program, it is the foundation for beginning to write more in-depth programs in Code::Blocks. As your programs increase in length and depth, the same basic steps apply. Happy programming!

Sources: https://www.cprogramming.com/tutorial/lesson1.html

https://en.wikipedia.org/wiki/Code::Blocks

Leave a Reply

Your email address will not be published. Required fields are marked *