We have upgraded our system to latest version of MyBB. We are very sorry for the downtime ! Read More.
Advertise Here | Remove Ads

Write and Run your first C++ program with CodeBlocks IDE !
  • 0 Vote(s) - 0 Average


Programming/Coding Write and Run your first C++ program with CodeBlocks IDE !
1
Hello everybody
I am learning several programming languages and want to share some of my knowledge with you all who have interest in programming and coding Thumbs Up
I am not an expert as I am still a newbie of programming, but I will try to explain, how can you run your first C++ program with CodeBlocks IDE.
So, lets start the journey Smile

Little information about C++

Before the initial standardization in 1998, C++ was developed by Bjarne Stroustrup at Bell Labs since 1979, as an extension of the C language as he wanted an efficient and flexible language similar to C, which also provided high-level features for program organization. C++ is an Object Oriented Programming. We can work with class, inheritance and other cool things in C++ which are not available in C.

What is CodeBlocks ?
Code::Blocks is a free, open-source cross-platform IDE that supports multiple compilers including GCC, Clang and Visual C++. It is developed in C++ using wxWidgets as the GUI toolkit. Using a plugin architecture, its capabilities and features are defined by the provided plugins. However, you can download Code::Blocks from their site : http://www.codeblocks.org
Go to their website and click Downloads from navigation and it will load the download page. From that page and choose/click  Download the binary release After that download the CodeBlocks according to your OS. If you are using windows then I will recommend to download the codeblocks-16.01mingw-setup.exe from Windows OS table.
Download and install CodeBlocks. I think you can install this software without any help or tutorial Wink So lets skip installation process/tutorial here Big Grin

Now, run CodeBlocks and from header menu go to File > New > Project. A pop-up window will appear and from that window choose Console Application. Please see the screenshot...
[Image: SDQ8aCol.jpg]

Select Console Application and click Go button. Now click Next button in the  next window and after that select C++ from the list box and click Next button again. Now it will show a window like below...
[Image: 4sHho2el.jpg]
In this window give a project title for your C++ program. Choose the destination folder for necessary files by clicking that three dots. After that click the Next button again. Now you should get a window like below...
[Image: UYzHiZbl.jpg]

In this window you will see two checkbox and those should be checked by default, if not then check them and click finish. Now we got our project and need to write/run our C++ code Thumbs Up
After finishing it, click/double click  Sources from left sidebar.
[Image: ycjFNU4l.jpg]

Now you should see a file call main.cpp simply click that filename and Code::Blocks will load the Hello World ! C++ program.
[Image: gNiE28xl.jpg]

You should get some C++ code like below...
Code:
#include <iostream>


using namespace std;

int main()
{
   cout << "Hello world!" << endl;
   return 0;
}

Its a simple program to print/show Hello World ! in the screen. Did you understand the code ?? If not then lets try to understand it...


Code:
#include <iostream>
iostream is a header file which made for input/output stream. Because we are displaying (output) the text so we have used iostream header file.

Code:
using namespace std;
The built in C++ library routines are kept in the standard namespace. That includes stuff like cout, cin, string, vector, map, etc. Because these tools are used so commonly, it's popular to add "using namespace std" at the top of your source code so that you won't have to type the std:: prefix constantly.

Code:
int main()
{

   return 0;
}
Its our main function. Our compiler will execute the main function codes. However, there are little big definition for using int main () and return 0. However the simple answer, is because the C++ standard requires main() to return int . As you probably know, the return value from the main() function is used by the runtime library as the exit code for the process. Both Unix and Win32 support the concept of a (small) integer returned from a process after it has finished. However, I will suggest you to read some theory about this. You can find some at online, I think Wink

Code:
cout << "Hello world!" << endl;
We have used cout for displaying our text "Hello World!". On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout . For formatted output operations, cout is used together with the insertion operator, which is written as << (i.e., two "less than" signs). Want more info about this ?? Please prefer some text or online books.. Because its little hard to explain everything here Smile

However, lets run the hello world program. To compile/run this program simply click F9 (windows  not sure about mac or others) and it should show you the output in a console like below...

[Image: 4pW9wv7l.jpg]

So finally we have run our first C++ program Big Grin .


Note : I have tried my best to provide you much information as much as I can. If you don't have knowledge about any programming and want to understand the hello world program of C++, then I will recommend you to study C++ to know more about it !! I have wrote this tutorial to show you how can you run your C++ program with CodeBlocks.. .

If I have made any mistake then please let me know.

Thanks




2
Everything here is allien to me as I have no knowledge in programming. Well, maybe oneday I may decide to try it out. Hopefully, it is not as difficult as I am thinking. Thanks for the tutorial anyway.

Reply





Forum Jump:


Users browsing this thread:
1 Guest(s)

Advertise Here | Remove Ads