📄 right1-3.htm
字号:
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>第 1 章</title>
<base target="rbottom">
<style>
<!--
.右标题 { font-size: 10pt; color: #000080; text-indent: 0; margin: 0 }
.右内容 { font-size: 10pt; text-align: left; text-indent: 0; line-height: 100%; margin:
0 }
-->
</style>
</head>
<body>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 5; top: -10"><img border="0" src="1.gif" width="63" height="70"></span></p>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"> </p>
<p style="line-height: 100%; text-indent: 0; margin: 0" class="右标题" align="left">
<span style="background-color: #CCFF99">第 1 章</span><span style="background-color: #CCFF99">
</span>><span style="background-color: #CCFF99"> 第 1 节 </span>><span style="background-color: #CCFF99">
1.3 简单I/O操作</span></p>
<hr color="#008000" size="1">
<p style="line-height: 150%; text-indent: 0; margin: 0" align="left"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">在程序中经常需要将数据输出到屏幕、打印机、存储器等,也经常需要从键盘接收用户输入的数据,这种输入输出操作统称为</font>I/O<font FACE="??ì?,SimSun" LANG="ZH-CN">操作。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">在</font>C++<font FACE="??ì?,SimSun" LANG="ZH-CN">中把数据的</font>I/O<font FACE="??ì?,SimSun" LANG="ZH-CN">称为数据流,它提供了强大的“流”处理功能,控制数据从一个位置流向另外一个位置。当数据从内存流向屏幕、打印机或硬盘时称为输出;当数据从键盘、硬盘流向内存时称为输入。</font>C++<font FACE="??ì?,SimSun" LANG="ZH-CN">用两个对象</font>cin<font FACE="??ì?,SimSun" LANG="ZH-CN">和</font>cout<font FACE="??ì?,SimSun" LANG="ZH-CN">实现标准的输入输出操作。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">cin<font FACE="??ì?,SimSun" LANG="ZH-CN">:它是</font>istream<font FACE="??ì?,SimSun" LANG="ZH-CN">类的对象,用来处理标准输入,即键盘输入。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">cout<font FACE="??ì?,SimSun" LANG="ZH-CN">:它是</font>ostream<font FACE="??ì?,SimSun" LANG="ZH-CN">类的对象,用来处理标准输出,即屏幕输出。</font></font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font FACE="oúì?,SimHei" LANG="ZH-CN" size="2">1.
使用抽取符和cin实现键盘输入</font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font FACE="??ì?,SimSun" LANG="ZH-CN" size="2">数据输入的格式为:</font></p>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">
cin
>> <font FACE="??ì?,SimSun" LANG="ZH-CN">表达式</font> >> <font FACE="??ì?,SimSun" LANG="ZH-CN">表达式…</font>
;</font></p>
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font FACE="oúì?,SimHei" LANG="ZH-CN" size="2">2.
使用插入操作符和cout实现屏幕输出</font></p>
<font SIZE="3">
<p ALIGN="justify" style="line-height: 150%; margin-top: 0; margin-bottom: 0"></font><font FACE="??ì?,SimSun" LANG="ZH-CN" size="2">数据输出的格式为:</font></p>
<p ALIGN="justify" style="line-height: 200%; margin-top: 0; margin-bottom: 0"><font size="2" color="#008000">
cout
<<<font FACE="??ì?,SimSun" LANG="ZH-CN">表达式</font> << <font FACE="??ì?,SimSun" LANG="ZH-CN">表达式…</font>
;</font></p>
<b>
<p style="line-height: 150%; text-indent: 0; margin: 0" align="left"><font size="2"> </font></b><font size="2"><a href="example1-2.htm"><font FACE="??ì?,SimSun" LANG="ZH-CN">【例</font>1-2<font FACE="??ì?,SimSun" LANG="ZH-CN">】</font></a>C++的I/O<font FACE="??ì?,SimSun" LANG="ZH-CN">操作。</font></font></p>
<p ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font FACE="oúì?,SimHei" LANG="ZH-CN" size="2">3.
控制输出格式</font></p>
<font SIZE="3">
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></font><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN">许多情况下,都需要控制输出结果的表现形式,如输出宽度、输出精度、输出格式等。</font>C++<font FACE="??ì?,SimSun" LANG="ZH-CN">的</font>iomanip.h<font FACE="??ì?,SimSun" LANG="ZH-CN">中定义了许多控制符,这些控制符可以直接插入到流中,控制数据的输出格式。</font></font></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN"><a href="example1-3.htm" target="_blank">【例</a></font><a href="example1-3.htm" target="_blank">1-3<font FACE="??ì?,SimSun" LANG="ZH-CN">】</font></a><font FACE="??ì?,SimSun" LANG="ZH-CN">输出</font>8<font FACE="??ì?,SimSun" LANG="ZH-CN">进制和</font>16<font FACE="??ì?,SimSun" LANG="ZH-CN">进制数。</font></font></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN"><a href="example1-4.htm" target="_blank">【例</a></font><a href="example1-4.htm" target="_blank">1-4<font FACE="??ì?,SimSun" LANG="ZH-CN">】</font></a><font FACE="??ì?,SimSun" LANG="ZH-CN">设置值的输出宽度。</font></font></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN"><a href="example1-5.htm" target="_blank">【例</a></font><a href="example1-5.htm" target="_blank">1-5<font FACE="??ì?,SimSun" LANG="ZH-CN">】</font></a><font FACE="??ì?,SimSun" LANG="ZH-CN">设置填充字符。</font></font></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN"><a href="example1-6.htm" target="_blank">【例</a></font><a href="example1-6.htm" target="_blank">1-6<font FACE="??ì?,SimSun" LANG="ZH-CN">】</font></a><font FACE="??ì?,SimSun" LANG="ZH-CN">设置对齐格式。</font></font></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2"><font FACE="??ì?,SimSun" LANG="ZH-CN"><a href="example1-7.htm" target="_blank">【例</a></font><a href="example1-7.htm" target="_blank">1-7<font FACE="??ì?,SimSun" LANG="ZH-CN">】</font></a><font FACE="??ì?,SimSun" LANG="ZH-CN">控制浮点数显示。</font></font></p>
<hr size="1" color="#008000">
<div style="position: absolute; top: 592; left: 12; width: 818; height: 19">
<div style="position: absolute; top: 43; left: -1; width: 818; height: 19">
</div>
</div>
<p style="line-height: 100%; margin-top: 0; margin-bottom: 0"><span style="position: absolute; left: 31; top: 637"><a href="right1-2.htm" target="_self"><img border="0" src="rightd1.gif" width="113" height="70"></a></span>
<span style="position: absolute; left: 500; top: 643"><a href="right1-4.htm" target="_self"><img border="0" src="rightd2.gif" width="124" height="63"></a></span></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -