Copyright ? 2012 Pearson Education, Inc. Chapter 3: Expressions and Interactivity Copyright ? 2012 Pearson Education, Inc. The cin Object Copyright ? 2012 Pearson Education, Inc. The cin Object ? Standard input object ? Like cout , requires iostream file ? Used to read input from keyboard ? Information retrieved from cin with >> ? Input is stored in one or more variables Copyright ? 2012 Pearson Education, Inc. The cin Object in Program 3-1 Copyright ? 2012 Pearson Education, Inc. The cin Object ? cin converts data to the type that matches the variable: int height; cout << "How tall is the room? "; cin >> height; Copyright ? 2012 Pearson Education, Inc. Displaying a Prompt ? A prompt is a message that instructs the user to enter data. ? You should always use cout to display a prompt before each cin statement. cout << "How tall is the room? "; cin >> height; Copyright ? 2012 Pearson Education, Inc. The cin Object ? Can be used to input more than one value: cin >> height >> width; ? Multiple values from keyboard must be separated by spaces ? Order is important: first value entered goes to first variable, etc. Copyright ? 2012 Pearson Education, Inc. The cin Object Gathers Multiple Values in Program 3-2 Copyright ? 2012 Pearson Education, Inc. The cin Object Reads Different Data Types in Program 3-3 Copyright ? 2012 Pearson Education, Inc. Mathematical Expressions
c 教学ppt课件 来自淘豆网m.daumloan.com转载请标明出处.