Tuesday, February 2, 2016

How to make simple hello world program in C++

Some of you may already experienced in programming but today we going to make a simple hello world program using C++. you can create hello world program from any IDE, Compiler, etc. but we going to use notepad instead and using TDM-GCC compiler, so the first thing that you have to do is download TDM-GCC compiler from http://tdm-gcc.tdragon.net/download
After you install the compiler it should be already installed PATH on windows for recognize the command of the compiler.


Now let's open notepad and write our code:



The samples code of hello world:
#include <iostream>

using namespace std;

int main()
{
cout << "Hello, World" << endl;
cin.get();
return 0;
}
After you copy the code then Save As file name or type CTRL+S then Save as file type as cpp like picture below:
Then click Save. Now were ready to compile the program, go to start > then click Run or just type Windows+R then on run dialog type "cmd" without quote, locate your cpp location using "cd 'folder location'" example : "cd Desktop"
now when you inside the file location type

g++ -c "filetype.cpp"
change the "filetype.cpp" into your cpp files without quote, example: g++ -c helloworld.cpp
if there's no error object files will appears then type another command:
g++ -o "your executable name" "filetype.o"
change the "your executable name" into the executable name that you desired then change the "filetype.o" into the object files that appear after you compile the cpp file, example: g++ -o helloworld helloworld.o

And there you go there must be hello world program appear then open it like you do to the same windows application



Video Tutorial : https://www.youtube.com/watch?v=YYl9C1byc5s

No comments:

Post a Comment