example7-7.htm
来自「Visual C++面向对象程序设计教程(配套习题资源)」· HTM 代码 · 共 54 行
HTM
54 行
<html>
<head>
<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>例7-7</title>
</head>
<body>
<blockquote>
<blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include
<iostream.h></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include
<fstream.h></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include
<string.h></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">void
main( )</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
<blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">ifstream
myf("d:\\myabc.txt",ios::nocreate);</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">if
(myf.fail( )) //<font FACE="??ì?,SimSun" LANG="ZH-CN">文件打开失败</font></font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
<blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout<<"file
no exist!"<<endl;</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">return;</font></p>
</blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">char
txt[255];</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">myf>>txt;</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">while
(!myf.eof( ))</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
<blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout<<txt<<endl;</font></p>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">myf>>txt;</font></p>
</blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
</blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
</blockquote>
</blockquote>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?