You just install Geany text editor if you dont like the default one and with some packages you will be all set up. So lets get started. As we said the first thing you will do is open the Terminal. Firstly we must make sure that we have all the necessary packages to start writing codes. Type this command in terminal
sudo apt-get build-essential
This will install the necessary libraries for C++ for you start writing and compiling code in this language. If you love to organize your projects you may want to create a folder in the Home directory that will hold all your C++ projects. I created a folder called Cplusplus inside Home directory. And here i will create different folders for my projects. For example for this tutorial i created a folder inside Cplusplus named Hello World.
Geany is perfect for writing C++ code. You can install it through Ubuntu Software Center or through terminal by typing this command
sudo apt-get install geany
Now open geany and paste this C++ code to test if you can compile and run your C++ programs.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
return 0;
}
Save this file inside folder in Home->Cplusplus->Hello World folders we created earlier and name it main.cpp or whatever you like to name your source files. Now in Terminal you must change your directory to where your source files are and then compile them.
cd Home/Cplusplus/Hello World
With this command we changed the current directory to the folder Hello World where our main.cpp file is. Now we are ready to compile and see if everything works.
g++ main.cpp -o hello
This command will compile the file main.cpp with g++ compiler and the executable file will be named hello. If everything is compiled we can run our program by calling the name of the executable as we named in the above command. Type this in terminal after compiling your source files to run them
And as you can see your program is successfully compiled and running. Happy coding thanks for reading.
0 comments :
Post a Comment