Thông tin tài liệu
C++ Programming Lecture Input/Output Manipulations The Hashemite University Computer Engineering Department (Adapted from the textbook slides) Outline Introduction Floating-Point Numbers; Scientific Notation Floating-Point Precision Field Width Trailing Zeros and Decimal Points Padding The Hashemite University Input/Output Manipulations I C++ provides various stream manipulators that perform formatting tasks Till now we have dealt with screen output using cout So, all these manipulators will format the text that appears on the screen Examples: Setting the precision of the displayed floating point numbers Setting the field width Showing trailing zeros and decimal point in floating point numbers Filling field with specific characters The Hashemite University Input/Output Manipulations II All the previous tasks or functions are provided via the iomanip library (short for input/output manipulation) So, when you want to use any of these functions you must include this library in your code #include using namespace std; The Hashemite University Input/Output Manipulations III These functions or operators are classified into: Sticky operators: Applied to all subsequent cout statements that come after calling the specified function Non-sticky operators: Applied only to the first cout statement that comes after calling the specified function The Hashemite University Floating-Point Numbers; Scientific Notation (scientific, fixed) scientific forces output of a floating point number in scientific notation: 1.946000e+009 Only one digit in the integer part of the floating point number and n digits after the floating point (depends on the precision value and by default its 6) and put the suitable power after the e exponent E.g.: cout
Ngày đăng: 12/10/2021, 21:08
Xem thêm: