So first we need to include our input out put library like this
#include<iostream>
Next we need to specify what exactly we will be using in thing library
using std::cout;
using namespace std;
So now you will learn a bit about functions that is the main function of you c++ program a function is a set of instructions that you can call any place the main function in executed when a program runs but enough of that just know that you will need it for these examples for now later we will talk more about functions
Sorry guys forgot to mention the importance of your semicolons ; this is what tell the complier that you have finished a statement of you miss out you semi colons your program simple wont run
This is you main function
int main(){}
So a simple program displaying Hello World would look something like
#include<iostream>//input out put library using std::cout; // specfiy to use cout the library int main() // main function of you c++ { cout << "Hello World"; // output Hello World in console system("pause"); // pause program }
if want run it go in dev C++ go to File > New > Source File
A blank page should pop up like below this is where you type you code
When your finish it should look like the this
You can run this by pressing F9 on your keyboard or going to Execute > Compile & Run on the menu bar
Now when you run it will notice a problem the Hello World and the Press any key yo continue... is joined and is on the same line
1. is to use the endl this mean enter a new line and is use like shown below
cout << "Hello World "<<endl;
cout << "Hello World "; cout << endl;
cout << "Hello World \n";
cout << "Hello World "; cout << "\n";
If you decided to do it the first way remember to specify that you will be using endl this is in the code below on line 4
#include<iostream>//input out put library using std::cout; // specfiy to use cout the library using std::endl; // enter new line int main() // main function of you c++ { cout << "Hello World"<<endl; // output Hello World in console system("pause"); // pause program }
Here is the code using \n instead
#include<iostream>//input out put library #include<iostream>//input out put library using std::cout; // specfiy to use cout the library int main() // main function of you c++ { cout << "Hello World \n"; // output Hello World in console system("pause"); // pause program }
#include<iostream>//input out put library using std::cout; // specfiy to use cout the library int main() // main function of you c++ { cout << "Hello "<<"World \n"; // output Hello World in console system("pause"); // pause program }
No comments:
Post a Comment