﻿<?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++博客-prabl</title><link>http://www.cppblog.com/prabl/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 08 Apr 2026 06:21:00 GMT</lastBuildDate><pubDate>Wed, 08 Apr 2026 06:21:00 GMT</pubDate><ttl>60</ttl><item><title>跨平台的C++</title><link>http://www.cppblog.com/prabl/archive/2006/05/19/7399.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Fri, 19 May 2006 02:02:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/05/19/7399.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/7399.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/05/19/7399.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/7399.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/7399.html</trackback:ping><description><![CDATA[今天装了linuxfans.org社区、由国内LINUX爱好者推出的Magic Linux。<br />
使用KWrite编写C++源码，然后在Shell里使用g++手动编译。<br />
在Windows里能运行的代码，放到这也照样可行。<br />
标准真好！<br /><img src ="http://www.cppblog.com/prabl/aggbug/7399.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-05-19 10:02 <a href="http://www.cppblog.com/prabl/archive/2006/05/19/7399.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>各种包含</title><link>http://www.cppblog.com/prabl/archive/2006/04/28/6411.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Fri, 28 Apr 2006 02:37:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/04/28/6411.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/6411.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/04/28/6411.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/6411.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/6411.html</trackback:ping><description><![CDATA[php可以使用include,require,include_once,require_once来将其它文件包含到当前文件中.<br />include和require的区别:<br />当被包含文件不存在时,include给出一个警告,并继续执行后面的代码;而require则会抛出一个错误,并停止执行代码.<br />include_once和require的区别同上.<br />include和include_once的区别在于:<br />如果文件已经包含进来了include_once不会再包含了,而include则继续包含.<br />require和require_once的区别同上.<img src ="http://www.cppblog.com/prabl/aggbug/6411.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-04-28 10:37 <a href="http://www.cppblog.com/prabl/archive/2006/04/28/6411.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP中的引用（&amp;）</title><link>http://www.cppblog.com/prabl/archive/2006/04/24/6123.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Mon, 24 Apr 2006 01:09:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/04/24/6123.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/6123.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/04/24/6123.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/6123.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/6123.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">&lt;?</span>
				<span style="COLOR: #000000">php<br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">引用</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> myclass<br />{<br />    </span>
				<span style="COLOR: #0000ff">var</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$name</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">var</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$age</span>
				<span style="COLOR: #000000">;<br />    </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000"> myclass(</span>
				<span style="COLOR: #800080">$name_</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">凌</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$age_</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">23</span>
				<span style="COLOR: #000000">)<br />    {<br />        </span>
				<span style="COLOR: #800080">$this</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> name </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$name_</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #800080">$this</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> age </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$age_</span>
				<span style="COLOR: #000000">;<br />    }<br />    </span>
				<span style="COLOR: #0000ff">function</span>
				<span style="COLOR: #000000"> showinfo(</span>
				<span style="COLOR: #800080">$obj</span>
				<span style="COLOR: #000000">)<br />    {<br />        </span>
				<span style="COLOR: #0000ff">echo</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">&lt;div&gt;\$</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #800080">$obj</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> -&gt; name = </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$this</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> name</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">;\$</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #800080">$obj</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> -&gt; age=</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #800080">$this</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> age</span>
				<span style="COLOR: #000000">.</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">&lt;/div&gt;</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000"> ;<br />    }<br />}<br /><br /></span>
				<span style="COLOR: #800080">$myfun</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> myclass();<br /></span>
				<span style="COLOR: #800080">$myfun</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> showinfo(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">myfun</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #800080">$myfun1</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> myclass(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">张三</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">); </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">无法理解</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #800080">$myfun1</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> showinfo(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">myfun1</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /></span>
				<span style="COLOR: #800080">$myfun2</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$myfun</span>
				<span style="COLOR: #000000">; </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">和$myfun指向同一个地方</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #800080">$myfun2</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-&gt;</span>
				<span style="COLOR: #000000"> showinfo(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">myfun2</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br /><br /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">简单数据类型的引用</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #800080">$a</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #800080">$b</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">&amp;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$a</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #800080">$b</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #0000ff">echo</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #800080">$a</span>
				<span style="COLOR: #000000">; </span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">是1不是0</span>
				<span style="COLOR: #008000">
						<br />
				</span>
				<span style="COLOR: #000000">?&gt;</span>
		</div>
<img src ="http://www.cppblog.com/prabl/aggbug/6123.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-04-24 09:09 <a href="http://www.cppblog.com/prabl/archive/2006/04/24/6123.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PHP的函数重载</title><link>http://www.cppblog.com/prabl/archive/2006/04/24/6122.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Mon, 24 Apr 2006 00:52:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/04/24/6122.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/6122.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/04/24/6122.html#Feedback</comments><slash:comments>13</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/6122.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/6122.html</trackback:ping><description><![CDATA[通用方法：（使用参数的默认值实现）
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">&lt;?</span><span style="COLOR: #000000">php<br /></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> myclass<br />{<br />    </span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$name</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$age</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> myclass(</span><span style="COLOR: #800080">$name_</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">凌</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$age_</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">23</span><span style="COLOR: #000000">)<br />    {<br />        </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$name_</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> age </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$age_</span><span style="COLOR: #000000">;<br />    }<br />    </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> showinfo(</span><span style="COLOR: #800080">$obj</span><span style="COLOR: #000000">)<br />    {<br />        </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;div&gt;\$</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$obj</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> -&gt; name = </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> name</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;\$</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$obj</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> -&gt; age=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> age</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;/div&gt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> ;<br />    }<br />}<br /><br /></span><span style="COLOR: #800080">$myfun</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> myclass();<br /></span><span style="COLOR: #800080">$myfun</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> showinfo(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">myfun</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #800080">$myfun1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> myclass(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">张三</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #800080">$myfun1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> showinfo(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">myfun1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #800080">$myfun2</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> myclass(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">李四</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">25</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #800080">$myfun2</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> showinfo(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">myfun2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #000000">?&gt;</span></div><p>另一种方式（使用系统函数实现）</p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">&lt;?</span><span style="COLOR: #000000">php<br /></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">函数重载</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> myfun<br />{<br />    </span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$name</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">var</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$age</span><span style="COLOR: #000000">;<br />    </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> myfun1(</span><span style="COLOR: #800080">$name_</span><span style="COLOR: #000000">)<br />    {<br />        </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$name_</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> age </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">23</span><span style="COLOR: #000000">;<br />    }<br />    </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> myfun2(</span><span style="COLOR: #800080">$name_</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$age_</span><span style="COLOR: #000000">)<br />    {<br />        </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$name_</span><span style="COLOR: #000000">;<br />        </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> age </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$age_</span><span style="COLOR: #000000">;<br />    }<br />    </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> myfun()<br />    {<br />        </span><span style="COLOR: #800080">$args_num</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">func_num_args</span><span style="COLOR: #000000">(); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">获取参数个数</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        </span><span style="COLOR: #800080">$args</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #008080">func_get_args</span><span style="COLOR: #000000">(); </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">获取参数列表</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        <br />        </span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">(</span><span style="COLOR: #800080">$args_num</span><span style="COLOR: #000000">)<br />        {<br />            </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000"><br />                </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> myfun1(</span><span style="COLOR: #800080">$args</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]);<br />                </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000"><br />                </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> myfun2(</span><span style="COLOR: #800080">$args</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$args</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]);<br />                </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br />            </span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">:</span><span style="COLOR: #000000"><br />                </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">凌</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br />                </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> age </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">23</span><span style="COLOR: #000000">;<br />                </span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br />        }<br />    }<br />    </span><span style="COLOR: #0000ff">function</span><span style="COLOR: #000000"> showinfo(</span><span style="COLOR: #800080">$obj</span><span style="COLOR: #000000">)<br />    {<br />        </span><span style="COLOR: #0000ff">echo</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;div&gt;\$</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$obj</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> -&gt; name = </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> name</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;\$</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$obj</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> -&gt; age=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">.</span><span style="COLOR: #800080">$this</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> age</span><span style="COLOR: #000000">.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">&lt;/div&gt;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> ;<br />    }<br />}<br /><br /></span><span style="COLOR: #800080">$myfun</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> myfun();<br /></span><span style="COLOR: #800080">$myfun</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> showinfo(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">myfun</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #800080">$myfun1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> myfun(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">张三</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #800080">$myfun1</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> showinfo(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">myfun1</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #800080">$myfun2</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> myfun(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">李四</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,</span><span style="COLOR: #000000">25</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #800080">$myfun2</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">-&gt;</span><span style="COLOR: #000000"> showinfo(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">myfun2</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #000000">?&gt;</span></div><img src ="http://www.cppblog.com/prabl/aggbug/6122.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-04-24 08:52 <a href="http://www.cppblog.com/prabl/archive/2006/04/24/6122.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>二维数组（附，书中的错误）</title><link>http://www.cppblog.com/prabl/archive/2006/04/12/5399.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Wed, 12 Apr 2006 08:15:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/04/12/5399.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/5399.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/04/12/5399.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/5399.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/5399.html</trackback:ping><description><![CDATA[
		<p>书上说到2D数组时，用了这个例子：</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #000000">#include </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">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> Cities </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">5</span>
				<span style="COLOR: #000000">;<br /></span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> Years </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">;<br /><br /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br />{<br />    </span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br />    <br />   <br />      </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000"> cities[Cities]</span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> <br />    {<br />          </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Gribble city</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,<br />          </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Gribble town</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,<br />          </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">New Gribble</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,<br />          </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">San Gribble</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,<br />          </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Gribble Vista</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">
						<br />    };<br />    <br />    <br />    <br />    </span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> maxtemps[Years][Cities] </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000">
						<br />    {<br />        {</span>
				<span style="COLOR: #000000">95</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">99</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">86</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">100</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">104</span>
				<span style="COLOR: #000000">},<br />        {</span>
				<span style="COLOR: #000000">95</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">97</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">90</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">106</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">102</span>
				<span style="COLOR: #000000">},<br />        {</span>
				<span style="COLOR: #000000">96</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">100</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">940</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">107</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">105</span>
				<span style="COLOR: #000000">},<br />        {</span>
				<span style="COLOR: #000000">97</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">102</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">89</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">108</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">104</span>
				<span style="COLOR: #000000">}<br />    };<br />    <br />    cout </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">Maximum tempevatures for 2002 - 2005\n\n</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">;<br />    <br />    </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> city </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">; city </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> Cities; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000"> city)<br />    {<br />        cout </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> cities[city] </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">: \t</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">;<br />        </span>
				<span style="COLOR: #0000ff">for</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> year </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">; year </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000"> Years; </span>
				<span style="COLOR: #000000">++</span>
				<span style="COLOR: #000000"> year)<br />            cout </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> maxtemps[year][city] </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">\t</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">;<br />        cout </span>
				<span style="COLOR: #000000">&lt;&lt;</span>
				<span style="COLOR: #000000"> endl;<br />    }<br />    <br />    cin.</span>
				<span style="COLOR: #0000ff">get</span>
				<span style="COLOR: #000000">();<br />    </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">;<br />}<br /></span>
		</div>
		<br />完了之后，书上说，可以这样定义cities 2D数组：
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">  cities[</span><span style="COLOR: #000000">25</span><span style="COLOR: #000000">][Cities]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> <br />    {<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble city</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble town</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">New Gribble</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">San Gribble</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble Vista</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br />    };</span></div>书上说：这样定义，你就保证每个地名不超过24个字符。当初看到这段代码，我百思不得其解：25行，每行5列（Cities常量）？？？也就是说，有25个城市，每个城市的名称不能超过4个字符（字符串还得加个“\0”），这是正确的吗？<br />编译器告诉我，这样写是错的！<br />按照自己的理解改成：
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">  cities[Cities][</span><span style="COLOR: #000000">25</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> <br />    {<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble city</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble town</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">New Gribble</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">San Gribble</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble Vista</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br />    };</span></div>顺利通过编译，并且结果和原例一样。<br />当然，改成string更简单，也更好理解。不过，这时候就是一维数组了：
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">   </span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">  cities[Cities]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> <br />    {<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble city</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble town</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">New Gribble</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">San Gribble</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,<br />          </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Gribble Vista</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br />    };</span></div>我更喜欢用string，因为我是从VB转过来的，习惯了string；同时，书上都说了，string是C++对C的扩充，是面向对象的～<img src ="http://www.cppblog.com/prabl/aggbug/5399.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-04-12 16:15 <a href="http://www.cppblog.com/prabl/archive/2006/04/12/5399.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>is_numeric的欠佳版本</title><link>http://www.cppblog.com/prabl/archive/2006/04/12/5395.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Wed, 12 Apr 2006 07:44:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/04/12/5395.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/5395.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/04/12/5395.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/5395.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/5395.html</trackback:ping><description><![CDATA[
		<p>书上有个例子，只允许用户输入数字，这个例子是用来计算高尔夫球结果的。把其中的核心提出来：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span>
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">#include </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: #008080"> 2</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> std;<br /></span>
				<span style="COLOR: #008080"> 4</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
				</span>
				<span style="COLOR: #008080"> 5</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /></span>
				<span style="COLOR: #008080"> 6</span>
				<span style="COLOR: #000000">
						<img id="Codehighlighter1_54_351_Open_Image" onclick="this.style.display='none'; Codehighlighter1_54_351_Open_Text.style.display='none'; Codehighlighter1_54_351_Closed_Image.style.display='inline'; Codehighlighter1_54_351_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_54_351_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_54_351_Closed_Text.style.display='none'; Codehighlighter1_54_351_Open_Image.style.display='inline'; Codehighlighter1_54_351_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span id="Codehighlighter1_54_351_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_54_351_Open_Text">
						<span style="COLOR: #000000">{<br /></span>
						<span style="COLOR: #008080"> 7</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> i;<br /></span>
						<span style="COLOR: #008080"> 8</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /></span>
						<span style="COLOR: #008080"> 9</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </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">"</span>
						<span style="COLOR: #000000">;<br /></span>
						<span style="COLOR: #008080">10</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">while</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #000000">!</span>
						<span style="COLOR: #000000">(cin </span>
						<span style="COLOR: #000000">&gt;&gt;</span>
						<span style="COLOR: #000000"> i))<br /></span>
						<span style="COLOR: #008080">11</span>
						<span style="COLOR: #000000">
								<img id="Codehighlighter1_120_263_Open_Image" onclick="this.style.display='none'; Codehighlighter1_120_263_Open_Text.style.display='none'; Codehighlighter1_120_263_Closed_Image.style.display='inline'; Codehighlighter1_120_263_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_120_263_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_120_263_Closed_Text.style.display='none'; Codehighlighter1_120_263_Open_Image.style.display='inline'; Codehighlighter1_120_263_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_120_263_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_120_263_Open_Text">
								<span style="COLOR: #000000">{<br /></span>
								<span style="COLOR: #008080">12</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />              cin.clear();<br /></span>
								<span style="COLOR: #008080">13</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />              </span>
								<span style="COLOR: #0000ff">while</span>
								<span style="COLOR: #000000"> (cin.</span>
								<span style="COLOR: #0000ff">get</span>
								<span style="COLOR: #000000">() </span>
								<span style="COLOR: #000000">!=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">'</span>
								<span style="COLOR: #000000">\n</span>
								<span style="COLOR: #000000">'</span>
								<span style="COLOR: #000000">)<br /></span>
								<span style="COLOR: #008080">14</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />                    </span>
								<span style="COLOR: #0000ff">continue</span>
								<span style="COLOR: #000000">;<br /></span>
								<span style="COLOR: #008080">15</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />              cout </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">"</span>
								<span style="COLOR: #000000">;<br /></span>
								<span style="COLOR: #008080">16</span>
								<span style="COLOR: #000000">
										<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
						</span>
						<span style="COLOR: #008080">17</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /></span>
						<span style="COLOR: #008080">18</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </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">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> i </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl; <br /></span>
						<span style="COLOR: #008080">19</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /></span>
						<span style="COLOR: #008080">20</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    system(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">PAUSE</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">);<br /></span>
						<span style="COLOR: #008080">21</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    <br /></span>
						<span style="COLOR: #008080">22</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /></span>
						<span style="COLOR: #008080">23</span>
						<span style="COLOR: #000000">
								<img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">24</span>
				<span style="COLOR: #000000">
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<p>当输入：a时，提示输入错误；当输入5a时，显示出5.这与我想象中（或者说，其它语言中的isnumeric函数）有一丝出入<br />原因应该出自cin，该如何解决？？？？<br /></p>
<img src ="http://www.cppblog.com/prabl/aggbug/5395.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-04-12 15:44 <a href="http://www.cppblog.com/prabl/archive/2006/04/12/5395.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>cin之于char[]和string</title><link>http://www.cppblog.com/prabl/archive/2006/04/12/5393.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Wed, 12 Apr 2006 07:17:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/04/12/5393.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/5393.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/04/12/5393.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/5393.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/5393.html</trackback:ping><description><![CDATA[
		<p>书上说，string可以看作char数组：<br />#include &lt;iostream&gt;</p>
		<p>using namespace std;</p>
		<p>int main()<br />{<br />    const int SIZE = 20;<br />    string str;<br />    char ch[SIZE];<br />    <br />    cin &gt;&gt; str;<br />    cin &gt;&gt; ch;<br />    cout &lt;&lt; str &lt;&lt; "," &lt;&lt; ch &lt;&lt; endl;<br /><br />    system("PAUSE");<br />    return 0;<br />}<br />在使用 cin &gt;&gt; 时，无论是string还是char[]，编译器都能通过编译。可是，当使用cin.getline()时：<br />#include &lt;iostream&gt;</p>
		<p>using namespace std;</p>
		<p>int main()<br />{<br />    const int SIZE = 20;<br />    string str;<br />    char ch[SIZE];<br />    <br />   <br />    cin.getline(ch,SIZE);<br />    cin.getline(str,SIZE);<br />    <br />    <br />    system("PAUSE");<br />    return 0;<br />}<br />编译器无法编译，出错信息：13（行号）  no matching function for call to `std::basic_istream&lt;char, std::char_traits&lt;char&gt; &gt;::getline(std::string&amp;, const int&amp;)' <br />不是说，string是char的数组吗？可是，为什么会出现没有匹配的函数？？？<br /><br />再有：<br />#include &lt;iostream&gt;<br />#include &lt;string&gt;<br />using namespace std;</p>
		<p>int main()<br />{<br />    const int SIZE = 20;<br />    string str;<br />    char ch[SIZE];<br />    char c;<br />   <br />    cin.get(c);<br />    cin.get(ch);<br />    cin.get(str);    <br />    <br />    system("PAUSE");<br />    return 0;<br />} <br />cin.get()只允许接受char类型的参数，不接受char[]、string类型的参数。所以，从cin.get(ch);开始，就无法编译了。<br /><br />（本人使用的编译器：Dev-C++ 4.9.9.2）<br /></p>
<img src ="http://www.cppblog.com/prabl/aggbug/5393.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-04-12 15:17 <a href="http://www.cppblog.com/prabl/archive/2006/04/12/5393.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C++读写文本文件</title><link>http://www.cppblog.com/prabl/archive/2006/04/12/5391.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Wed, 12 Apr 2006 07:01:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/04/12/5391.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/5391.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/04/12/5391.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/5391.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/5391.html</trackback:ping><description><![CDATA[
		<p>#include &lt;iostream&gt;<br />#include &lt;fstream&gt;</p>
		<p>using namespace std;</p>
		<p>int main()<br />{<br />    const char filename[] = "mytext.txt";<br />    ofstream o_file;<br />    ifstream i_file;<br />    string out_text;<br />    <br />    //写<br />    o_file.open(filename);<br />    for (int i = 1; i &lt;= 10; i++)<br />    {<br />         o_file &lt;&lt; "第" &lt;&lt; i &lt;&lt; "行\n"; //将内容写入到文本文件中 <br />    } <br />    o_file.close();<br />    <br />    //读<br />    i_file.open(filename);<br />    if (i_file.is_open())<br />    {<br />                         while (i_file.good())<br />                         {<br />                              i_file &gt;&gt; out_text; //将读取的内容存储到变量out_text中 <br />                              cout &lt;&lt; out_text &lt;&lt; endl; //在控制台输出读取的内容。为什么最后一行的内容会出现两次 <br />                         } <br />    }<br />    else<br />        cout &lt;&lt; "打开文件：" &lt;&lt; filename &lt;&lt; " 时出错！"; <br />    i_file.close();<br />    <br />    system("PAUSE");<br />    return 0;<br />}<br /><br />为什么总会将最后一行显示两遍？我的循环似乎没错呀。</p>
<img src ="http://www.cppblog.com/prabl/aggbug/5391.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-04-12 15:01 <a href="http://www.cppblog.com/prabl/archive/2006/04/12/5391.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>typedef示例</title><link>http://www.cppblog.com/prabl/archive/2006/04/03/4938.html</link><dc:creator>蕃豆仁</dc:creator><author>蕃豆仁</author><pubDate>Mon, 03 Apr 2006 06:36:00 GMT</pubDate><guid>http://www.cppblog.com/prabl/archive/2006/04/03/4938.html</guid><wfw:comment>http://www.cppblog.com/prabl/comments/4938.html</wfw:comment><comments>http://www.cppblog.com/prabl/archive/2006/04/03/4938.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/prabl/comments/commentRss/4938.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/prabl/services/trackbacks/4938.html</trackback:ping><description><![CDATA[
		<p>#include &lt;iostream&gt;</p>
		<p>typedef int prablint; //定义别名</p>
		<p>int main()<br />{<br />    using namespace std;<br />    prablint a = 0;<br />    cout &lt;&lt; sizeof(a) &lt;&lt; endl;<br />    cout &lt;&lt; sizeof(int) &lt;&lt; endl;<br />    <br />    system("PAUSE");<br />    return 0;<br />}<br /></p>
<img src ="http://www.cppblog.com/prabl/aggbug/4938.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/prabl/" target="_blank">蕃豆仁</a> 2006-04-03 14:36 <a href="http://www.cppblog.com/prabl/archive/2006/04/03/4938.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>