Beruflich Dokumente
Kultur Dokumente
cpp 1
2 // A first program in C++
Outline
Comments
3 #include <iostream>
Written between /* and */ or following a //.
1. Comments
4
Improve program readability and do not cause the
5 int main() computer to perform any action. 2. Load <iostream>
6 { 3. main
preprocessor directive
7 std::cout << "Welcome to C++!\n";
Message to the C++ preprocessor.3.1 Print "Welcome
8
to C++\n"
Lines beginning with # are preprocessor directives.
9 return 0; // indicate that program ended successfully
#include <iostream> tells3.2 theexit
preprocessor
(returnto 0)
10 } include
C++ the contents
programs containofone
theor <iostream>,
filemore which
functions, one of
includes
which be main operations (such as printing to
input/output
must
the screen). Program Output
Welcome to C++! Parenthesis are used to indicate a function
int means
Prints the string of characters that main
contained between the an integer value.
"returns"
quotation marks. More in Chapter 3.
return is a way to exit a function
from a function. A left
The entire line, including brace { begins
std::cout, the the
<< body of every function
return 0, in this case,
operator, and a right to
thatstring "Welcome
means the } ends it. and
braceC++!\n"
the program terminatedthe semicolon (;), is called a statement.
normally.
11 }
2.4 exit (return 0)