Our first C++ programs must tell the computer to produce output; otherwise we would never know if the programs were executed correctly, or even if they were executed at all.
storm.cis.fordham.com
,
the filename ends with
.C
(uppercase);
on other machines, the filename might end with
.CPP
or
.CXX
.
std::cout
means
“the outside world, considered as a destination for output”.
This output will be a stream of characters;
that’s what the
c
in
cout
stands for.
A
namespace
is a family of things that share the same last name,
in this case the name
std
.
Last name first, first name last.
No space between the two colons.
#include
a header file.
<<
(“put to”) operator points towards the destination.
No space between
<’s
;
type it exactly the way I do.
"
double-quoted"
strings and the invisible newline (\n
).
24 characters, followed by the newline character,
followed by the terminating zero character.
;
)
at the end of each statement.
main
.
The lines
int main() {mark the start of the
main
function;
the line
}marks the end. The body of the function is the statements between the two curly braces. Conventional to indent the body of the function by one tab. The parentheses will not be used until later; we still have to write them even though they’re empty.
int
from the
main
function to the operating system:
EXIT_SUCCESS
for success,
EXIT_FAILURE
for failure.
Another header file.
system("PAUSE");
storm.cis.fordham.edu
:
/usr/include/c++/14/iostream
/usr/include/c++/14/cstdlib
for
EXIT_SUCCESS
c++ -v
storm.cis.fordham.edu
:
find / -type f -name iostream 2> /dev/null
//
for single-line/* */
for multi-linestorm.cis.fordham.edu
and explore your account.
See below.
dime1.C
:
flag.C
:
Put in a
using directive
to get on a first-name basis with
cout
.
Do all the output with only one statement, not ten statements.
Run the program and deposit the output into a file named
flag.txt
.
Copy the program and flag.txt
into your
public_html
directory so everybody can see these two files.
//This is only one statement, not a complete C++ program. //Output three copies of the ASCII "alarm" character. std::cout << "\a\a\a\n";
return
?
//Not a complete C++ program, just a fragment. return EXIT_SUCCESS; std::cout << "Never reaches this point.\n"; }
chinese.C
:
an attempt to output the Chinese characters
上
下
川
(up, down, stream).