Chapter Three键盘输入和屏幕输出.ppt

  1. 1、本文档共15页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Chapter Three键盘输入和屏幕输出

Author: J. de Wet Chapter Three: Keyboard Input and Screen Output(键盘输入和屏幕输出) Simple keyboard input(简单的键盘输入) Manipulators(流操纵符) Single-character input and output(单个字符的输入和输出) Keyboard Input and Screen Output In C++, data stream objects are used to perform basic input and output of data to and from various devices such as the keyboard and the screen. A stream is a data communication object connected to an input or output device.(在C++中,数据流对象用于在各种不同的设备如键盘和屏幕上执行基本的数据输入和输出操作。所谓流,就是与输入输出设备相关联的数据通信对象。) 流插入运算符 用于将数据输出到cout. 流提取运算符用于从键盘读取数据. Simple keyboard input 使用cin时,可以认为数据是先输入到输入流中,然后按照箭头所指的方向流入到内存中的变量里。 使用cout时,可以认为数据是先输入到输出流中,然后按照箭头所指的方向送到屏幕显示。 Manipulators(流操纵符) Manipulator endl was used to modify input and output data streams. The mainpulator endl was used in previous programs to skip to the start of a new line on the screen. (流操纵符用于对输入和输出数据流进行修改。如endl它的作用是将光标移到一个新行的起始位置。) A manipulator can appear anywhere in a series of insertion or extraction opperations.(流操纵符可以出现在一个连续的流插入和流提取运算符中的任何位置。如下:) cout endl endl endl can be used anywhere endl; Manipulators(流操纵符) setw is used to set the width of a data field.用于设置数据域的宽度,指的是数据项在屏幕上所点的列数。 int num1=123; coutsetw(4)num1; setfill is used to change the “padding” character from a space to any other character.用于把占位符从空格改变为其他字符 coutsetw(5)setfill(‘*’)num1endl; 结果:**123 #include iomanip setw只对输出流中的下一个数据项起作用,而setfill将对送入输出流中的所有后继数据项都起作用。如:P3D Manipulators(流操纵符) setprecision is used to specify the number of digits of a number to display.用于指定要显示的数据的位数 double num=123.45678 coutnum; coutsetprecision(7)numendl; coutfixedsetprecision(2)numendl; 123.457(默认情况下,只显示6位数字) 123.4568 123.46 fixed在setprecision(2)之前说明小数点后显示2位 流操纵符fixed和setprecision将一直对输出流中的后继数据项起作用。 Single-character input and output 空白字符:Tab、Enter和空格键。 char ch;

文档评论(0)

yan698698 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档