How to start C++ Programming?First-Time Programmers
If you are new learner and want to start C++ coding then It will be very helpful for you.
Do you have similar website/ Product?
Show in this page just for only
$2 (for a month)
0/60
0/180
Comments
/* ...... */ these are use for multi line comments
//.... these are use for multi line comments
#include
It is called a preprocessor directive and begins with a # sign. They are processed before compilation. The directive "#include
The "using namespace std;" statement declares std as the default namespace used in this program. cout and endl belong to the std namespace.
int main() { body }
It defines the main() function. It is the entry point of program execution. main() is required to return an integer.
return 0;
It terminates the main() function and returns a value of 0 to the operating system.
You can write your first C++ program that prints the message "My First Program" on the display console by following some steps:
2.Build the Executable Code
1.Write the Source Code
Enter the source codes using a programming text editor such that NotePad++ for Windows or gedit for UNIX/Linux/Mac or an Interactive Development Environment (IDE).
1.Enter the line numbers on the left side, which were added to help in the explanation.
2.Save the source file as "Myfirstprogram.cpp" or with any meaningful name you want.
3.A C++ source file should be saved with a file extension of ".cpp".
Enter the following code:
#include using namespace std; int main() { // Program begins here cout <<"My First Program" << endl; // Print the line with in commas return 0; // it terminates main() } |
2.Build the Executable Code
If you are on IDE then click on the "Build" button.
If you are using any other text editor with the GNU GCC compiler then start a CMD Shell or Terminal and issue the following commands:
// For Windows >g++ -o Myfirstprogram.exe Myfirstprogram.cpp //For UNIX/Linux/Mac $ g++ -oMyfirstprogram Myfirstprogram.cpp |
3.Run the Executable Code
1.If you are using IDE then click the "Run" button.
2.If you are using the Text Editor with GNU GCC compiler then issue the following command from CMD Shell or Terminal :
// Windows > My First Program // UNIX/Linux/Mac $ ./My First Program |
This is very simple code .Hope new programmers find it helpful. |
CONTINUE READING
First-Time Programmers
Ayesha
Tech writer at newsandstory