The C++ language defines several headers, which contain information that is either necessary or useful to your program. For this program, the header <iostream> is needed.
The line usingnamespacestd; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++.
The line int main() is the main function where program execution begins.
The next line cout<< "Hello World"; causes the message "Hello World" to be displayed on the screen.
The next line return 0; terminates main( )function and causes it to return the value 0 to the calling process.
The << operator, called the insertion operator, is used to send information to the output stream.
The >> operator, called the extraction operator, is used to get information from the input stream.
Strings are used for storing text.
To use strings, you must include an additional headerfile in the source code, the <string> library:
The + operator can be used between strings to add them together to make a new string. This is called concatenation:
A string in C++ is actually an object, which contain functions that can perform certain operations on strings. For example, you can also concatenate strings with the append() function:
It is possible to use the extraction operator >> on cin to display a string entered by a user: