18. A Simple Program: Adding Two Integers(Cont) Concatenating stream insertion operations Use multiple stream insertion operators in a single statement Stream insertion operation knows how to output each type of data Also called chaining or cascadia ing Example e std: i cout <<sum is < number1 number 2 < std: : end Outputs" Sum 1s“ Then, outputs sum of number 1 and number 2 Then, outputs newline and flushes output buffer o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 11 18.3 A Simple Program: Adding Two Integers (Cont.) • Concatenating stream insertion operations – Use multiple stream insertion operators in a single statement • Stream insertion operation knows how to output each type of data – Also called chaining or cascading – Example • std::cout << "Sum is " << number1 + number2 << std::endl; - Outputs "Sum is “ - Then, outputs sum of number1and number2 - Then, outputs newline and flushes output buffer
18.4 C++ Standard Library C++ programs Built from pieces called classes and functions C++ Standard library Rich collections of existing classes and functions Reusable in new applications Usea“ building-block” approach to create programs. Avoid reinventing the wheel. Use existing pieces wherever possible. Called software reuse, this practice is central to object-oriented programming. o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 12 18.4 C++ Standard Library • C++ programs – Built from pieces called classes and functions • C++ Standard Library – Rich collections of existing classes and functions • Reusable in new applications • Use a “building-block” approach to create programs. Avoid reinventing the wheel. Use existing pieces wherever possible. Called software reuse, this practice is central to object-oriented programming
13 Software Engineering Observation 18.2 When programming in C++, you typically will use the following building blocks: classes and functions from the c++ Standard Library, classes and functions you and your colleagues create and classes and functions from various popular third- party libraries. o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 13 Software Engineering Observation 18.2 When programming in C++, you typically will use the following building blocks: classes and functions from the C++ Standard Library, classes and functions you and your colleagues create and classes and functions from various popular third-party libraries
14 Performance and Portability Tip Using C++ Standard library functions and classes instead of writing your own versions can improve program performance, because they are written to perform efficiently. This technique also shortens program development time. improve program portability, because they are included in every C++ implementation o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 14 Performance and Portability Tip Using C++ Standard Library functions and classes instead of writing your own versions can improve program performance, because they are written to perform efficiently. This technique also shortens program development time. improve program portability, because they are included in every C++ implementation
15 18.5 Header Files C++ Standard library header files Each contains a portion of the standard library Function prototypes for the related functions Definitions of various class types and functions Constants needed by those functions Instruct"the compiler on how to interface with library and user-written components Header file names ending in ·Are“old- style header files Superseded by the C++ Standard library header files Use #inc lude directive to include class in a program o 2007 Pearson Education, Inc. All rights reserved
© 2007 Pearson Education, Inc. All rights reserved. 15 18.5 Header Files • C++ Standard Library header files – Each contains a portion of the Standard Library • Function prototypes for the related functions • Definitions of various class types and functions • Constants needed by those functions – “Instruct” the compiler on how to interface with library and user-written components – Header file names ending in .h • Are “old-style”header files • Superseded by the C++ Standard Library header files – Use #include directive to include class in a program