﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-追求卓越</title><link>http://www.cppblog.com/tyouwei/</link><description>我的信念：精益求精;   
我的理想：成立一个具有影响力的互联网公司。</description><language>zh-cn</language><lastBuildDate>Sat, 18 Apr 2026 06:54:27 GMT</lastBuildDate><pubDate>Sat, 18 Apr 2026 06:54:27 GMT</pubDate><ttl>60</ttl><item><title>关于#include&lt;stdlib.h&gt;的使用</title><link>http://www.cppblog.com/tyouwei/archive/2011/08/31/154789.html</link><dc:creator>唐有炜</dc:creator><author>唐有炜</author><pubDate>Wed, 31 Aug 2011 07:16:00 GMT</pubDate><guid>http://www.cppblog.com/tyouwei/archive/2011/08/31/154789.html</guid><wfw:comment>http://www.cppblog.com/tyouwei/comments/154789.html</wfw:comment><comments>http://www.cppblog.com/tyouwei/archive/2011/08/31/154789.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tyouwei/comments/commentRss/154789.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tyouwei/services/trackbacks/154789.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #include&lt;stdlib.h&gt;是C语言中的一个头文件，首先，stdlib.h的解释<br />*Purpose:<br />* This include file contains the function declarations for commonly<br />* used library functions which either don't fit somewhere else, or,<br />* cannot be declared in the normal place for other reasons.<br /><br />&nbsp;&nbsp;&nbsp; 意思是一些常用的函数，但是又不知道把它们放到哪里合适，因此就都放到了stdlib.h这个头文件中。<br />stdlib.h可以提供一些函数与符号常量，具体如下：<br />根据ISO标准，stdlib.h提供以下类型：<br />size_t, wchar_t, div_t, ldiv_t, lldiv_t<br /><br />常量<br />NULL, EXIT_FAILURE, EXIT_SUCESS, RAND_MAX, MB_CUR_MAX<br />函数<br />atof, atoi, atol, strtod, strtof, strtols, strtol, strtoll, strtoul, strtoull, rand, srand, callc, free, maloc, realloc, abort, atexit, exit, getenv, system, bsearch, qsort, abs, div, labs, ldiv, llabs, tlldiv, mblen, mbtowc, wctomb, mbstowcs, wcstombs<img src ="http://www.cppblog.com/tyouwei/aggbug/154789.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tyouwei/" target="_blank">唐有炜</a> 2011-08-31 15:16 <a href="http://www.cppblog.com/tyouwei/archive/2011/08/31/154789.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于#include &lt;stdio.h&gt; 的使用</title><link>http://www.cppblog.com/tyouwei/archive/2011/08/31/154786.html</link><dc:creator>唐有炜</dc:creator><author>唐有炜</author><pubDate>Wed, 31 Aug 2011 07:09:00 GMT</pubDate><guid>http://www.cppblog.com/tyouwei/archive/2011/08/31/154786.html</guid><wfw:comment>http://www.cppblog.com/tyouwei/comments/154786.html</wfw:comment><comments>http://www.cppblog.com/tyouwei/archive/2011/08/31/154786.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tyouwei/comments/commentRss/154786.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tyouwei/services/trackbacks/154786.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 在使用标准函数库中的输入输出函数时，编译系统要求程序提供有关的信息（例如对这些输入输出函数的声明），#include&lt;<a href="http://baike.baidu.com/view/538727.htm" target="_blank">stdio.h</a>&gt;的作用就是用来提供这些信息的，stdio.h是C编译系统提供的一个文件名，stdio是&#8220;standard input &amp; output&#8221;的缩写，即有关标准输入输出的信息。 
<div class="spctrl"></div>　　在程序中用到系统提供的标准函数库中的输入输出函数时，应在程序的开头写上一行：#include"stdio.h"或者是#include&lt;stdio.h&gt;<img src ="http://www.cppblog.com/tyouwei/aggbug/154786.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tyouwei/" target="_blank">唐有炜</a> 2011-08-31 15:09 <a href="http://www.cppblog.com/tyouwei/archive/2011/08/31/154786.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++的数据类型</title><link>http://www.cppblog.com/tyouwei/archive/2011/07/06/150301.html</link><dc:creator>唐有炜</dc:creator><author>唐有炜</author><pubDate>Wed, 06 Jul 2011 07:28:00 GMT</pubDate><guid>http://www.cppblog.com/tyouwei/archive/2011/07/06/150301.html</guid><wfw:comment>http://www.cppblog.com/tyouwei/comments/150301.html</wfw:comment><comments>http://www.cppblog.com/tyouwei/archive/2011/07/06/150301.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tyouwei/comments/commentRss/150301.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tyouwei/services/trackbacks/150301.html</trackback:ping><description><![CDATA[<strong><em><span style="font-family: 宋体; font-size: 18pt">字</span><span style="font-family: 宋体; font-size: 18pt">符集和词汇</span></em></strong> 
<div v:shape="_x0000_s1026">
<div></div>
<div><span style="font-family: Constantia; font-size: 26pt"><strong>&nbsp;&nbsp;&nbsp;&nbsp;</strong></span><span style="font-family: 宋体; font-size: 14pt">大、小写的英文字母</span><span style="font-family: Constantia; font-size: 26pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Constantia; font-size: 14pt">A ~ Z , a ~ z</span> </div>
<div><span style="font-family: Constantia; font-size: 26pt">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: 宋体; font-size: 14pt">阿拉伯数字</span><span style="font-family: Constantia; font-size: 26pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Constantia; font-size: 12pt">&nbsp;&nbsp;<strong>&nbsp;</strong></span><strong><span style="font-family: Constantia; font-size: 10pt">&nbsp;</span><span style="font-family: Constantia; font-size: 12pt">&nbsp;0</span><span style="font-family: Constantia; font-size: 14pt">~ 9</span> </strong></div>
<div><span style="font-family: Constantia; font-size: 26pt"><strong>&nbsp;&nbsp;&nbsp;&nbsp;</strong></span><span style="font-family: 宋体; font-size: 14pt">符号</span><span>&nbsp;&nbsp;&nbsp;<strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +&nbsp;-&nbsp;*&nbsp;/&nbsp;%&nbsp;&lt;&nbsp;=&nbsp;&gt;&nbsp;!&nbsp;(&nbsp;)&nbsp;[&nbsp;]&nbsp;{&nbsp;}&nbsp;~</strong> 
<div><span style="font-family: Constantia; font-size: 10pt"><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;&nbsp;^&nbsp;|&nbsp;?&nbsp;#&nbsp;\&nbsp;&nbsp; _&nbsp;.&nbsp;,&nbsp;;&nbsp;&#8220;&nbsp;:&nbsp;</strong><span style="font-family: 宋体; font-size: 14pt"><strong>空格&nbsp;</strong></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span> 
<div><p:colorscheme colors="#ffffff,#000000,#dbf5f9,#04617b,#0f6fc6,#009dd9,#e2d700,#85dfd0"></p:colorscheme><p:colorscheme colors="#ffffff,#000000,#dbf5f9,#04617b,#0f6fc6,#009dd9,#e2d700,#85dfd0"></p:colorscheme><span style="font-size: 18pt"><strong><em>&nbsp; </em></strong></span>
<div class="O" v:shape="_x0000_s1026">
<div style="mso-line-spacing: '100 20 0'; mso-margin-left-alt: 172; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><span style="font-family: Constantia"><span style="position: absolute; font-family: 'Wingdings 2'; color: #0bd0d9; font-size: 18pt; top: 0.04em; left: -5.12%; mso-special-format: bullet"><strong><em>&#8212;</em></strong></span></span><strong><em><span style="font-family: Constantia; font-size: 18pt; mso-ascii-font-family: Constantia; mso-fareast-font-family: 宋体; mso-hansi-font-family: Constantia" lang="EN-US">C++</span><span style="font-family: 宋体; font-size: 18pt; mso-ascii-font-family: Constantia; mso-fareast-font-family: 宋体; mso-hansi-font-family: Constantia" lang="X-NONE">常用的关键字</span></em><span style="font-family: 宋体; mso-ascii-font-family: Constantia; mso-fareast-font-family: 宋体; mso-hansi-font-family: Constantia" lang="EN-US">&nbsp;</span></strong>&nbsp; <br /><br />
<table dir="ltr" cellspacing="0" cellpadding="0" width="412" height="136">
<tbody>
<tr>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; width: 38px; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">auto</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">bool</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">break</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">case</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">char</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">class</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">const</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; width: 18px; height: 31px; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">continue</span></nobr></div></td></tr>
<tr>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">default</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">delete</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">do</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">double</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">else</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">enum</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">extern</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">false</span></nobr></div></td></tr>
<tr>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">float</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">for</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">friend</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">goto</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">if</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">inline</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">int</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">long</span></nobr></div></td></tr>
<tr>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">new</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">operator</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">private</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">protected</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; width: 97px; height: 38px; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">public</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">register</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">return</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">short</span></nobr></div></td></tr>
<tr>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">signed</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">sizeof</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">static</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">struct</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">switch</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">template</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">this</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#ccd5ea" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">true</span></nobr></div></td></tr>
<tr>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">typedef</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">union</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">unsigned</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">virtual</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">void</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<div style="text-align: justify; mso-char-wrap: 1; mso-kinsoku-overflow: 1"><nobr><span style="font-family: 'Times New Roman'; color: black; font-size: 24pt; mso-ascii-font-family: 'Times New Roman'; mso-fareast-font-family: 宋体; mso-hansi-font-family: 'Times New Roman'" lang="EN-US">volatile</span></nobr></div></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23" width="52">
<p>&nbsp;</p></td>
<td style="border-bottom: white 1px solid; border-left: white 1px solid; vertical-align: top; border-top: white 1px solid; border-right: white 1px solid" bgcolor="#e7ebf5" height="23">
<p>&nbsp;</p></td></tr></tbody></table></div></div></div></div></div></div> <img src ="http://www.cppblog.com/tyouwei/aggbug/150301.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tyouwei/" target="_blank">唐有炜</a> 2011-07-06 15:28 <a href="http://www.cppblog.com/tyouwei/archive/2011/07/06/150301.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Visual C++常用数据类型转换</title><link>http://www.cppblog.com/tyouwei/archive/2011/07/06/150295.html</link><dc:creator>唐有炜</dc:creator><author>唐有炜</author><pubDate>Wed, 06 Jul 2011 07:09:00 GMT</pubDate><guid>http://www.cppblog.com/tyouwei/archive/2011/07/06/150295.html</guid><wfw:comment>http://www.cppblog.com/tyouwei/comments/150295.html</wfw:comment><comments>http://www.cppblog.com/tyouwei/archive/2011/07/06/150295.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tyouwei/comments/commentRss/150295.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tyouwei/services/trackbacks/150295.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; 我们先定义一些常见类型变量借以说明：<br /><code>int i = 100;<br />long l = 2001;<br />float f=300.2;<br />double d=12345.119;<br />char username[]=＂女侠程佩君＂;<br />char temp[200];<br />char *buf;<br />CString str;<br />_variant_t v1;<br />_bstr_t v2;</code><br />　　一、其它数据类型转换为字符串<br /><br />　　短整型（int）<br /><br /><code>itoa（i,temp,10）;///将i转换为字符串放入temp中,最后一个数字表示十进制<br />itoa（i,temp,2）; ///按二进制方式转换 </code><br />　　长整型（long）<br /><br /><code>ltoa（l,temp,10）;</code><br />　　二、从其它包含字符串的变量中获取指向该字符串的指针<br /><br />　　CString变量<br /><br /><code>str = ＂2008北京奥运＂;<br />buf = （LPSTR）（LPCTSTR）str; </code><br />　　BSTR类型的_variant_t变量<br /><br /><code>v1 = （_bstr_t）＂程序员＂;<br />buf = _com_util::ConvertBSTRToString（（_bstr_t）v1）;</code><br />　　三、字符串转换为其它数据类型<br /><br /><code>strcpy（temp,＂123＂）; </code><br />　　短整型（int）<br /><br /><code>i = atoi（temp）; </code><br />　　长整型（long）<br /><br /><code>l = atol（temp）; </code><br />　　浮点（double）<br /><br /><code>d = atof（temp）;</code><br />　　四、其它数据类型转换到CString<br /><br />　　使用CString的成员函数Format来转换,例如:<br /><br />　　整数（int）<br /><br /><code>str.Format（＂%d＂,i）; </code><br />　　浮点数（float）<br /><br /><code>str.Format（＂%f＂,i）; </code><br />　　字符串指针（char *）等已经被CString构造函数支持的数据类型可以直接赋值 <br /><br /><code>str = username;</code><br />　　五、BSTR、_bstr_t与CComBSTR<br /><br />　　CComBSTR、_bstr_t是对BSTR的封装,BSTR是指向字符串的32位指针。<br /><br />char *转换到BSTR可以这样: BSTR b=_com_util::ConvertStringToBSTR（＂数据＂）;///使用前需要加上头文件comutil.h<br /><br />　　反之可以使用<br /><br /><code>char *p=_com_util::ConvertBSTRToString（b）;</code><br />　　六、VARIANT 、_variant_t 与 COleVariant<br /><br />　　VARIANT的结构可以参考头文件VC98\Include\OAIDL.H中关于结构体tagVARIANT的定义。<br /><br />　　对于VARIANT变量的赋值：首先给vt成员赋值，指明数据类型，再对联合结构中相同数据类型的变量赋值，举个例子：<br /><br /><code>VARIANT va;<br />int a=2001;<br />va.vt=VT_I4;///指明整型数据<br />va.lVal=a; ///赋值</code><br />　　对于不马上赋值的VARIANT，最好先用Void VariantInit（VARIANTARG FAR* pvarg）;进行初始化,其本质是将vt设置为VT_EMPTY,下表我们列举vt与常用数据的对应关系:<br /><br /><code>unsigned char bVal; VT_UI1 <br />short iVal; VT_I2 <br />long lVal; VT_I4 <br />float fltVal; VT_R4 <br />double dblVal; VT_R8 <br />VARIANT_BOOL boolVal; VT_BOOL <br />SCODE scode; VT_ERROR <br />CY cyVal; VT_CY <br />DATE date; VT_DATE <br />BSTR bstrVal; VT_BSTR <br />IUnknown FAR* punkVal; VT_UNKNOWN <br />IDispatch FAR* pdispVal; VT_DISPATCH <br />SAFEARRAY FAR* parray; VT_ARRAY|* <br />unsigned char FAR* pbVal; VT_BYREF|VT_UI1 <br />short FAR* piVal; VT_BYREF|VT_I2 <br />long FAR* plVal; VT_BYREF|VT_I4 <br />float FAR* pfltVal; VT_BYREF|VT_R4 <br />double FAR* pdblVal; VT_BYREF|VT_R8 <br />VARIANT_BOOL FAR* pboolVal; VT_BYREF|VT_BOOL <br />SCODE FAR* pscode; VT_BYREF|VT_ERROR <br />CY FAR* pcyVal; VT_BYREF|VT_CY <br />DATE FAR* pdate; VT_BYREF|VT_DATE <br />BSTR FAR* pbstrVal; VT_BYREF|VT_BSTR <br />IUnknown FAR* FAR* ppunkVal; VT_BYREF|VT_UNKNOWN <br />IDispatch FAR* FAR* ppdispVal; VT_BYREF|VT_DISPATCH <br />SAFEARRAY FAR* FAR* pparray; VT_ARRAY|* <br />VARIANT FAR* pvarVal; VT_BYREF|VT_VARIANT <br />void FAR* byref; VT_BYREF </code><br />　　 _variant_t是VARIANT的封装类，其赋值可以使用强制类型转换，其构造函数会自动处理这些数据类型。<br /><br />　　例如：<br /><br /><code>long l=222;<br />ing i=100;<br />_variant_t lVal（l）;<br />lVal = （long）i;</code><br />　　COleVariant的使用与_variant_t的方法基本一样，请参考如下例子：<br /><br /><code>COleVariant v3 = ＂字符串＂, v4 = （long）1999;<br />CString str =（BSTR）v3.pbstrVal;<br />long i = v4.lVal;</code><br />　　七、其它<br /><br />　　对消息的处理中我们经常需要将WPARAM或LPARAM等32位数据（DWORD）分解成两个16位数据（WORD）,例如：<br /><br /><code>LPARAM lParam;<br />WORD loValue = LOWORD（lParam）;///取低16位<br />WORD hiValue = HIWORD（lParam）;///取高16位 </code><br />　　对于16位的数据（WORD）我们可以用同样的方法分解成高低两个8位数据（BYTE）,例如:<br /><br /><code>WORD wValue;<br />BYTE loValue = LOBYTE（wValue）;///取低8位<br />BYTE hiValue = HIBYTE（wValue）;///取高8位 </code>    <img src ="http://www.cppblog.com/tyouwei/aggbug/150295.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tyouwei/" target="_blank">唐有炜</a> 2011-07-06 15:09 <a href="http://www.cppblog.com/tyouwei/archive/2011/07/06/150295.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++的程序结构</title><link>http://www.cppblog.com/tyouwei/archive/2011/07/06/150293.html</link><dc:creator>唐有炜</dc:creator><author>唐有炜</author><pubDate>Wed, 06 Jul 2011 07:02:00 GMT</pubDate><guid>http://www.cppblog.com/tyouwei/archive/2011/07/06/150293.html</guid><wfw:comment>http://www.cppblog.com/tyouwei/comments/150293.html</wfw:comment><comments>http://www.cppblog.com/tyouwei/archive/2011/07/06/150293.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tyouwei/comments/commentRss/150293.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tyouwei/services/trackbacks/150293.html</trackback:ping><description><![CDATA[下面我们从一个最简单的程序入手看一个C++程序的组成结构。 
<table border="0" cellspacing="1" cellpadding="10">
<tbody>
<tr>
<td color="#008000">
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000">//</span><span style="color: #008000">My&nbsp;first&nbsp;program&nbsp;&nbsp;in&nbsp;C++&nbsp;</span><span style="color: #008000"><br /></span><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{<br />&nbsp;cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;&#8220;Hello&nbsp;World</span><span style="color: #000000">!</span><span style="color: #000000">&#8221;;<br />&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /><br /></span></div>
<p><br />结果如右图：<br /></font></p>
<p>&nbsp;</p></td>
<td valign="top">
<p>&nbsp;</p>
<p><br /><br /><br />Hello World! </p></td></tr></tbody></table>
<p>&nbsp;</p>
<p>上面左侧显示了我们的第一个程序的源代码，代码文件名称为hellowworld.cpp。右边显示了程序被编译执行后的输出结果。编辑和编译一个程序的方法取决于你用的是什么编译器，根据它是否有图形化的界面及版本的不同，编译方法也有可能不同，具体请参照你所使用的编译器的使用说明。</p>
<p>以上程序是多数初学者学会写的第一个程序，它的运行结果是在屏幕上打出&#8221;Hello World!&#8221;这句话。 虽然它可能是C++可写出的最简单的程序之一，但其中已经包含了每一个C++程序的基本组成结构。 下面我们就逐个分析其组成结构的每一部分：</p>
<h3>// My first program in C++</h3>
<p>这是注释行。所有以两个斜线符号(//)开始的程序行都被认为是注释行，这些注释行是程序员写在程序源代码内，用来对程序作简单解释或描述的， 对程序本身的运行不会产生影响。在本例中， 这行注释对本程序是什么做了一个简要的描述。<br /><br /></p>
<h3># include &lt; iostream &gt; </h3>
<p>以<span style="font-weight: bold">#</span>标志开始的句子是预处理器的指示语句。它们不是可执行代码，只是对编译器作出指示。在本例中这个句子# include &lt; iostream.h &gt; 告诉编译器的预处理器将输入输出流的标准头文件(iostream.h)包括在本程序中。这个头文件包括了C++中定义的基本标准输入-输出程序库的声明。此处它被包括进来是因为在本程序的后面部分中将用到它的功能。<br /><br /></p>
<h3>using namespace std;</h3>
<p>C++标准函数库的所有元素都被声明在一个名空间中，这就是std名空间。因此为了能够访问它的功能，我们用这条语句来表达我们将使用标准名空间中定义的元素。这条语句在使用标准函数库的C++程序中频繁出现，本教程中大部分代码例子中也将用到它。<br /><br /></p>
<h3>int main()</h3>
<p>这一行为主函数(main function)的起始声明。main function是所有C++程序的运行的起始点。 不管它是在代码的开头，结尾还是中间 &#8211; 此函数中的代码总是在程序开始运行时第一个被执行。并且，由于同样的原因，所有C++程序都必须有一个main function。<br />main 后面跟了一对圆括号（），表示它是一个函数。C++中所有函数都跟有一对圆括号 （），括号中可以有一些输入参数。如例题中显示，主函数(main function)的内容紧跟在它的声明之后，由花括号 （{}）括起来。 <br /><br /></p>
<h3>cout &lt;&lt; &#8220;Hellow World!&#8221;; </h3>
<p>这个语句在本程序中最重要。 cout 是C++中的标准输出流(通常为控制台，即屏幕)，这句话把一串字符串（本例中为&#8221;Hello World&#8221;）插入输出流（控制台输出）中。cout 在的声明在头文件iostream.h中，所以要想使用cout 必须将该头文件包括在程序开始处。<br />注意这个句子以分号(;)结尾 。分号标示了一个语句的结束，C++的每一个语句都必须以分号结尾。 (C++ 程序员最常犯的错误之一就是忘记在语句末尾写上分号) 。<br /><br /></p>
<h3>return 0;</h3>
<p>返回语句(return) 引起主函数 main()执行结束，并将该语句后面所跟代码(在本例中为0) 返回。这是在程序执行没有出现任何错误的情况下最常见的程序结束方式。在后面的例子中你会看到所有C++程序都以类似的语句结束。<br /><br />你可能注意到并不是程序中的所有的行都会被执行。程序中可以有注释行（以//开头），有编译器预处理器的指示行（以#开头），然后有函数的声明（本例中main函数），最后是程序语句（例如调用cout &lt;&lt;），最后这些语句行全部被括在主函数的花括号({})内。<br />在C++中，语句的分隔是以分号(;)为分隔符的。分行写代码只是为了更方便人阅读。<br /><br />以下程序包含更多的语句：</p>
<table border="0" cellspacing="1" cellpadding="10">
<tbody>
<tr>
<td color="#008000">
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000">//</span><span style="color: #008000">&nbsp;my&nbsp;second&nbsp;program&nbsp;in&nbsp;C++</span><span style="color: #008000"><br /></span><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main&nbsp;()<br />{<br />cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">Hello&nbsp;World!&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">;<br />cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">I'm&nbsp;a&nbsp;C++&nbsp;program</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}&nbsp;</span></div><br />结果如右图：</td>
<td valign="top">
<p>&nbsp;</p>
<p><br /><br />Hello World! I'm a C++ program <br /></p></td></tr></tbody></table>
<p>&nbsp;</p>
<p>在这个例子中，我们在两个不同的语句中调用了cout &lt;&lt; 函数两次。再一次说明分行写程序代码只是为了我们阅读方便，因为这个main 函数也可以被写为以下形式而没有任何问题:</p>
<div main program C++ () { cout &lt;&lt; Hello ?; return 0; } ? World! I?m to><br /></div>
<p>为方便起见，我们也可以把代码分为更多的行来写：<br /></p>
<div main ()>{<br />cout &lt;&lt;<br />"Hello World!";<br />cout<br />&lt;&lt; "I'm a C++ program";<br />return 0;<br />}<br /></div>
<p>它的运行结果将和上面的例子完全一样。</p>
<p>这个规则对预处理器指示行（以#号开始的行）并不适用，因为它们并不是真正的语句。它们由预处理器读取并忽略，并不会生成任何代码。因此他们每一个必须单独成行，末尾不需要分号(;)<br /></p>
<h3>注释 (Comments)</h3>
<p>注释(comments)是源代码的一部分，但它们会被编译器忽略。它们不会生成任何执行代码。 使用注释的目的只是使程序员可以在源程序中插入一些说明解释性的内容。 <br />C++ 支持两中插入注释的方法: <br /></p>
<div color="#008000">// line comment<br />/* block comment */ <br /></font></div>
<p>第一种方法为行注释，它告诉编译器忽略从//开始至本行结束的任何内容。第二种为块注释（段注释），告诉编译器忽略在/*符号和*/符号之间的所有内容，可能包含多行内容。</p>
<p>在以下我们的第二个程序中，我们插入了更多的注释。</p>
<p>&nbsp;</p>
<table border="0" cellspacing="1" cellpadding="10">
<tbody>
<tr>
<td color="#008000"><font my program in C++ second>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000">/*</span><span style="color: #008000">with&nbsp;more&nbsp;comments&nbsp;</span><span style="color: #008000">*/</span><span style="color: #000000"><br />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main&nbsp;()<br />{<br />cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">Hello&nbsp;World!&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;says&nbsp;Hello&nbsp;World!</span><span style="color: #008000"><br /></span><span style="color: #000000">cout&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">I'm&nbsp;a&nbsp;C++&nbsp;program</span><span style="color: #000000">"</span><span style="color: #000000">;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;says&nbsp;I'm&nbsp;a&nbsp;C++&nbsp;program</span><span style="color: #008000"><br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}&nbsp;</span></div><br />结果如右图：<br /></font></td>
<td valign="top">
<p>&nbsp;</p>
<p><br /><br />Hello World! I'm a C++ program <br /></p></td></tr></tbody></table><br />如果你在源程序中插入了注释而没有用//符号或/*和*/符号，编译器会把它们当成C++的语句，那么在编译时就会出现一个或多个错误信息。 <br /> <img src ="http://www.cppblog.com/tyouwei/aggbug/150293.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tyouwei/" target="_blank">唐有炜</a> 2011-07-06 15:02 <a href="http://www.cppblog.com/tyouwei/archive/2011/07/06/150293.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++程序</title><link>http://www.cppblog.com/tyouwei/archive/2011/07/06/150289.html</link><dc:creator>唐有炜</dc:creator><author>唐有炜</author><pubDate>Wed, 06 Jul 2011 05:54:00 GMT</pubDate><guid>http://www.cppblog.com/tyouwei/archive/2011/07/06/150289.html</guid><wfw:comment>http://www.cppblog.com/tyouwei/comments/150289.html</wfw:comment><comments>http://www.cppblog.com/tyouwei/archive/2011/07/06/150289.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tyouwei/comments/commentRss/150289.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tyouwei/services/trackbacks/150289.html</trackback:ping><description><![CDATA[1.输出：This is a C++ program.。<br />
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">This&nbsp;is&nbsp;a&nbsp;C++&nbsp;progrmme.</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div>
<p><br />2.求a和b两个数之和。</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,b,sum;<br />cout&lt;&lt;"请输入两个整数：";<br />cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">a</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">b;<br />sum</span><span style="color: #000000">=</span><span style="color: #000000">a</span><span style="color: #000000">+</span><span style="color: #000000">b;<br />cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">sum=</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">sum</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}</span></div>
<p>3.求两个数中的最大值。</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;max(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y);<br />&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,b,m;<br />cout&lt;&lt;&#8220;请输入两个整数：&#8221;<br />cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">a</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">b;<br />m</span><span style="color: #000000">=</span><span style="color: #000000">max(a,b);<br />cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">max=</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">m</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /><br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;max(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y)<br />{</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;z;<br /></span><span style="color: #0000ff">if</span><span style="color: #000000">(x</span><span style="color: #000000">&gt;</span><span style="color: #000000">y)<br />z</span><span style="color: #000000">=</span><span style="color: #000000">x;<br /></span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;z</span><span style="color: #000000">=</span><span style="color: #000000">y;<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;z;<br />}</span></div>
<p><br />4.输入输出学号和成绩。</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #0000ff">class</span><span style="color: #000000">&nbsp;Student<br />{</span><span style="color: #0000ff">private</span><span style="color: #000000">&nbsp;:<br />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;num;<br />&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;score;<br /></span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;:<br />&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;setdata()<br />&nbsp;&nbsp;{cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">num;<br />&nbsp;&nbsp;&nbsp;cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">score;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;display()<br />&nbsp;&nbsp;{cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">num=</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">num</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br />&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">score=</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">score</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br />&nbsp;&nbsp;};<br />};<br />Student&nbsp;stud1&nbsp;,stud2;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{stud1.setdata();<br />stud2.setdata();<br />stud1.display();<br />stud2.display();<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /></span></div>
<p><br />5.求三个数中的最小者。</p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;f(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;z);<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;a,b,c;<br />cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">a</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">b</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">c;<br />c</span><span style="color: #000000">=</span><span style="color: #000000">f(a,b,c);<br />cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">c</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;f(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;z)<br />{</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;m;<br /></span><span style="color: #0000ff">if</span><span style="color: #000000">(x</span><span style="color: #000000">&lt;</span><span style="color: #000000">y)&nbsp;m</span><span style="color: #000000">=</span><span style="color: #000000">x;<br /></span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;m</span><span style="color: #000000">=</span><span style="color: #000000">y;<br /></span><span style="color: #0000ff">if</span><span style="color: #000000">(z</span><span style="color: #000000">&lt;</span><span style="color: #000000">m)<br />m</span><span style="color: #000000">=</span><span style="color: #000000">z;<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;m;<br />}</span></div>
<p><br />6.三个数排序。<a href="/Files/tyouwei/三个数排序.rar">三个数排序.rar</a></p>
<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br />{</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;sort(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;z);<br /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,y,z;<br />cout&lt;&lt;"请输入三个数："&lt;&lt;endl;<br />cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">x</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">y</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">z;<br />sort(x,y,z);<br /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br />}<br /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;sort(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y,</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;z)<br />{</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;temp;<br /></span><span style="color: #0000ff">if</span><span style="color: #000000">(x</span><span style="color: #000000">&gt;</span><span style="color: #000000">y)&nbsp;<br />{temp</span><span style="color: #000000">=</span><span style="color: #000000">x;<br />x</span><span style="color: #000000">=</span><span style="color: #000000">y;<br />y</span><span style="color: #000000">=</span><span style="color: #000000">temp;<br />}<br /></span><span style="color: #0000ff">if</span><span style="color: #000000">(z</span><span style="color: #000000">&lt;</span><span style="color: #000000">x)<br />cout</span><span style="color: #000000">&lt;&lt;"排序如下："&lt;&lt;</span><span style="color: #000000">z</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">x</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">y</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(z</span><span style="color: #000000">&lt;</span><span style="color: #000000">y)<br />cout<span style="color: #000000">&lt;&lt;"排序如下："</span></span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">x</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">z</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">y</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;cout<span style="color: #000000">&lt;&lt;"排序如下："</span></span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">x</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">y</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">z</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">'</span><span style="color: #000000">,</span><span style="color: #000000">'</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br />}</span></div>
<p><br /><br /><br />&nbsp;</p> <img src ="http://www.cppblog.com/tyouwei/aggbug/150289.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tyouwei/" target="_blank">唐有炜</a> 2011-07-06 13:54 <a href="http://www.cppblog.com/tyouwei/archive/2011/07/06/150289.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>