C++
Important Links
C++ Program
How to write, compile and run the first C++ program. :-
#include <iostream.h>
#include<conio.h>
void main() {
clrscr();
cout << "Welcome to C++ Programming.";
getch();
}
#include <iostream.h>
using namespace std;
int main()
{
cout << "Hello this is C++";
}
Output :-
#include<iostream.h> includes the standard input output library functions. It provides cin and cout methods for reading from input and writing to output respectively.
#include includes the console input output library functions. The getch() function is defined in conio.h file.
#include includes the console input output library functions. The getch() function is defined in conio.h file.
Header files are included at the beginning. Here iostream is a header file which provides us with input & output streams. Header files contained predeclared function libraries, which can be used by users for their ease.
using namespace std :-
The line using namespace std; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++.
Using namespace std, tells the compiler to use standard namespace. Namespace collects identifiers used for class, object and variables. NameSpace can be used by two ways in a program, either by the use of using statement at the beginning, like we did in above mentioned program or by using name of namespace as prefix before the identifier with scope resolution (::) operator.
Example : std::cout << "itechxpert";
Using namespace std, tells the compiler to use standard namespace. Namespace collects identifiers used for class, object and variables. NameSpace can be used by two ways in a program, either by the use of using statement at the beginning, like we did in above mentioned program or by using name of namespace as prefix before the identifier with scope resolution (::) operator.
Example : std::cout << "itechxpert";
main() is the function which holds the executing part of program its return type is int.
The line int main() is the main function where program execution begins.
void main() The main() function is the entry point of every program in C++ language. The void keyword specifies that it returns no value.
The line int main() is the main function where program execution begins.
void main() The main() function is the entry point of every program in C++ language. The void keyword specifies that it returns no value.
cout :-
cout is Standard output stream. The cout object in C++ is an object of class ostream. It is used to display the output to the standard output device i.e. monitor.
cout <<, is used to print anything on screen, same as printf in C language. cin and cout are same as scanf and printf, only difference is that you do not need to mention format specifiers like, %d for int etc, in cout & cin.
cout <<, is used to print anything on screen, same as printf in C language. cin and cout are same as scanf and printf, only difference is that you do not need to mention format specifiers like, %d for int etc, in cout & cin.
return 0 :-
The next line return 0; terminates main( )function and causes it to return the value 0 to the calling process.
getch() The getch() function asks for a single character. Until you press any key, it blocks the screen.
How to compile and run the C++ program.
There are 2 ways to compile and run the C++ program, by menu and by shortcut.
By menu :-
Now click on the compile menu then compile sub menu to compile the c++ program.
Then click on the run menu then run sub menu to run the c++ program.
By shortcut
press ctrl+f9 keys compile and run the program directly.
You can view the user screen any time by pressing the alt+f5 keys.
Now press Esc to return to the turbo c++ console.
By menu :-
By shortcut
press ctrl+f9 keys compile and run the program directly.
You can view the user screen any time by pressing the alt+f5 keys.
Now press Esc to return to the turbo c++ console.