Can be removed through the use of using statements Standard output stream

Can be removed through the use of using statements

This preview shows page 9 - 18 out of 75 pages.

Can be removed through the use of using statements Standard output stream object std::cout » “Connected” to screen » Defined in input/output stream header file <iostream>
Image of page 9
10 First Program in C++: Printing a Line of Text (Cont.) Stream insertion operator << Value to right (right operand) inserted into left operand Example » std::cout << "Hello"; Inserts the string "Hello" into the standard output Displays to the screen Escape characters A character preceded by "\" » Indicates “special” character output Example » "\n" Cursor moves to beginning of next line on the screen
Image of page 10
11 Common Programming Error 2.2 Omitting the semicolon at the end of a C++ statement is a syntax error. (Again, preprocessor directives do not end in a semicolon.) A syntax error occurs when the compiler encounters code that violates C++’s language rules (i.e., its syntax). The compiler normally issues an error message to help the programmer locate and fix the incorrect code. (cont…)
Image of page 11
12 Common Programming Error 2.2 Syntax errors are also called compiler errors, compile-time errors or compilation errors, because the compiler detects them during the compilation phase. You will be unable to execute your program until you correct all the syntax errors in it. As you’ll see, some compilation errors are not syntax errors.
Image of page 12
13 First Program in C++: Printing a Line of Text (Cont.) return statement One of several means to exit a function When used at the end of main » The value 0 indicates the program terminated successfully » Example return 0;
Image of page 13
14 Good Programming Practice 2.3 Many programmers make the last character printed by a function a newline ( \n ). This ensures that the function will leave the screen cursor positioned at the beginning of a new line.
Image of page 14
15 Escape sequence Description \n Newline. Position the screen cursor to the beginning of the next line. \t Horizontal tab. Move the screen cursor to the next tab stop. \r Carriage return. Position the screen cursor to the beginning of the current line; do not advance to the next line. \a Alert. Sound the system bell. \\ Backslash. Used to print a backslash character. \' Single quote. Use to print a single quote character. \" Double quote. Used to print a double quote character. Escape sequences
Image of page 15
16 Good Programming Practice 2.4 Indent the entire body of each function one level within the braces that delimit the body of the function. This makes a program’s functional structure stand out and helps make the program easier to read. Set a convention for the size of indent you prefer, then apply it uniformly. The tab key may be used to create indents, but tab stops may vary.
Image of page 16
17 Modifying Our First C++ Program Two examples Print text on one line using multiple statements (Fig. 2.3) » Each stream insertion resumes printing where the previous one stopped Print text on several lines using a single statement (Fig. 2.4) » Each newline escape sequence positions the cursor to the beginning of the next line » Two newline characters back-to-back outputs a blank line
Image of page 17
Image of page 18

You've reached the end of your free preview.

Want to read all 75 pages?

  • Summer '19
  • C++ Programming, relational operator, standard output, circum

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes