﻿<?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++博客-polly study cs-随笔分类-VC++学习</title><link>http://www.cppblog.com/polly-yang/category/16832.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 30 Jul 2012 11:57:12 GMT</lastBuildDate><pubDate>Mon, 30 Jul 2012 11:57:12 GMT</pubDate><ttl>60</ttl><item><title>vs + opencv 常见错误</title><link>http://www.cppblog.com/polly-yang/archive/2012/07/30/185613.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Mon, 30 Jul 2012 03:57:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2012/07/30/185613.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/185613.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2012/07/30/185613.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/185613.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/185613.html</trackback:ping><description><![CDATA[Q:Link Error 2019 无法解析的外部符号&nbsp; _cvCreateImage<br />A:应将解决方案平台改为win64。<br />工具栏上方的解决方案平台&#8212;》点击下拉菜单&#8212;》配置管理器&#8212;》活动解决方案平台&#8212;》新建&#8212;》键入获选着新平台&#8212;》x64<br />问题就解决啦！哈哈！ <br /><br /><br /><br />Q：Error C1189 Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]<br />A:Go to the project properties (Project menu, Properties).&nbsp; Set 'Use of MFC' to "Use MFC in a Shared DLL".&nbsp; You have to make this change for both the debug and release configurations<img src ="http://www.cppblog.com/polly-yang/aggbug/185613.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2012-07-30 11:57 <a href="http://www.cppblog.com/polly-yang/archive/2012/07/30/185613.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>CString 、 string  、 const char*、int、double之间的相互转换</title><link>http://www.cppblog.com/polly-yang/archive/2012/07/24/184890.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Tue, 24 Jul 2012 12:34:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2012/07/24/184890.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/184890.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2012/07/24/184890.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/184890.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/184890.html</trackback:ping><description><![CDATA[<p><span style="font-family: Times New Roman; font-size: 14pt">我们在写程序时，常常会遇到类型转换的问题。现总结一些常见的类型转换。</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">1，const char*（C风格字符串）与string之间转换：</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;（1） const char*可以直接对string类型赋值，例如：</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* pchar = "qwerasdf";</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; stringstr = pchar;</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; （2） string通过c_str()函数转换为C风格字符串，例如：</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string str = "qwerasdf";</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* pchar = str.c_str();</span></p>
<p><span style="font-size: 18px"></span>&nbsp;</p>
<p><span style="font-family: Times New Roman; font-size: 14pt">2，const char*类型可以直接给CString类型赋值，例如：</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const char* pchar = "qwerasdf";</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString str = pchar;</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">3，string类型变量转为为Cstring类型变量</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CString类型变量可以直接给string类型变量赋值，但是string类型不能对CString类型直接赋值。通过前两类</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;转换我们可以得到，</span><span style="font-family: Times New Roman; font-size: 14pt">string类型变量转换为const char*类型，然后再直接赋值就可以了。例如：</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString cstr；</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sring str = &#8220;asdasd&#8221;；</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cstr = str.c_str();</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;同理，CStrng类型变量先转换为string类型在调用c_str()函数就可以完成向</span><span style="font-family: Times New Roman; font-size: 14pt">const char*类型的转换。例如：</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString cStr = "adsad";</span><span style="font-size: 18px">&nbsp;&nbsp;&nbsp;</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str = cStr;&nbsp;&nbsp;</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* pchar = str.c_str();<br /></span><span style="font-family: Times New Roman; font-size: 14pt">4，double，int转string<br /></span></p>
<p><span style="font-size: 18px"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Times New Roman; font-size: 14pt">double temp;</span><br />&nbsp;&nbsp;&nbsp;<span style="font-family: Times New Roman; font-size: 14pt">stringstream strStream;</span><br />&nbsp;&nbsp;&nbsp;<span style="font-family: Times New Roman; font-size: 14pt">strStream&lt;&lt;temp;</span><br />&nbsp;&nbsp;&nbsp;<span style="font-family: Times New Roman; font-size: 14pt">string ss = strStream.str()</span>&nbsp;<br /><br /><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;string 转double，int&nbsp;</span><br /><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;string.atoi&nbsp;&nbsp;&nbsp;,&nbsp;&nbsp;&nbsp;string.atof</span></p>
<p><span style="font-family: Times New Roman; font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp; 从上面我们可以上面看出，通过类型之间的相互转化，会使本来要通过复杂的函数来完成的类型转换变得简单易懂。</span></p><img src ="http://www.cppblog.com/polly-yang/aggbug/184890.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2012-07-24 20:34 <a href="http://www.cppblog.com/polly-yang/archive/2012/07/24/184890.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个容易上手的XML解析器TinyXml</title><link>http://www.cppblog.com/polly-yang/archive/2012/07/24/184820.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Tue, 24 Jul 2012 00:17:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2012/07/24/184820.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/184820.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2012/07/24/184820.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/184820.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/184820.html</trackback:ping><description><![CDATA[<p style="text-indent: 21pt"><span style="font-family: 宋体; font-size: 10pt">读取和设置</span><span style="font-family: Verdana; font-size: 10pt">xml</span><span style="font-family: 宋体; font-size: 10pt">配置文件是最常用的操作，试用了几个</span><span style="font-family: Verdana; font-size: 10pt">C++</span><span style="font-family: 宋体; font-size: 10pt">的</span><span style="font-family: Verdana; font-size: 10pt">XML</span><span style="font-family: 宋体; font-size: 10pt">解析器，个人感觉</span><span style="font-family: Verdana; font-size: 10pt">TinyXML</span><span style="font-family: 宋体; font-size: 10pt">是使用起来最舒服的，因为它的</span><span style="font-family: Verdana; font-size: 10pt">API</span><span style="font-family: 宋体; font-size: 10pt">接口和</span><span style="font-family: Verdana; font-size: 10pt">Java</span><span style="font-family: 宋体; font-size: 10pt">的十分类似，面向对象性很好。</span><span style="font-family: Verdana; font-size: 10pt"><!--?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /--></span></p>
<p style="text-indent: 21pt"><span style="font-family: Verdana; font-size: 10pt">TinyXML</span><span style="font-family: 宋体; font-size: 10pt">是一个开源的解析</span><span style="font-family: Verdana; font-size: 10pt">XML</span><span style="font-family: 宋体; font-size: 10pt">的解析库，能够用于</span><span style="font-family: Verdana; font-size: 10pt">C++</span><span style="font-family: 宋体; font-size: 10pt">，能够在</span><span style="font-family: Verdana; font-size: 10pt">Windows</span><span style="font-family: 宋体; font-size: 10pt">或</span><span style="font-family: Verdana; font-size: 10pt">Linux</span><span style="font-family: 宋体; font-size: 10pt">中编译。这个解析库的模型通过解析</span><span style="font-family: Verdana; font-size: 10pt">XML</span><span style="font-family: 宋体; font-size: 10pt">文件，然后在内存中生成</span><span style="font-family: Verdana; font-size: 10pt">DOM</span><span style="font-family: 宋体; font-size: 10pt">模型，从而让我们很方便的遍历这棵</span><span style="font-family: Verdana; font-size: 10pt">XML</span><span style="font-family: 宋体; font-size: 10pt">树。</span></p>
<p style="text-indent: 21pt"><span style="font-family: Verdana; font-size: 10pt">DOM</span><span style="font-family: 宋体; font-size: 10pt">模型即文档对象模型，是将整个文档分成多个元素（如书、章、节、段等），并利用树型结构表示这些元素之间的顺序关系以及嵌套包含关系。<br />&nbsp;&nbsp;&nbsp;&nbsp;不过TinyXml需要使用者手动释放new出的内存。初学C++者往往容易造成内存泄露。</span></p> <img src ="http://www.cppblog.com/polly-yang/aggbug/184820.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2012-07-24 08:17 <a href="http://www.cppblog.com/polly-yang/archive/2012/07/24/184820.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GetWindowRect与GetClientRect的区别</title><link>http://www.cppblog.com/polly-yang/archive/2012/02/13/165507.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Mon, 13 Feb 2012 12:01:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2012/02/13/165507.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/165507.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2012/02/13/165507.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/165507.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/165507.html</trackback:ping><description><![CDATA[<p><font color="#0000ff">先调用GetWindowRect后再调用ScreenToClient,这个时候得到的rect和直接使用GetClientRect得到的值是相等的。有时候需要获得窗口矩形的大小和客户区矩形的大小二者的值，故需要分别调用GetWindowRect和GetClientRect。如果只需要获得客户区矩形的大小，调用GetClientRect就行了。<font size="3">GetWindowRect</font>和GetClientRect函数的说明如下：</font></p>
<p><strong>CWnd::GetClientRect</strong>&nbsp;<wbr>&nbsp;<wbr><br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> void GetClientRect( LPRECT lpRect ) const;<br /><em><strong>Parameters:</strong><br />lpRect<br /></em>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> Points to a RECT structure or a CRect object to receive the client coordinates. The left and top members will be 0. The right and bottom members will contain the width and height of the window.<br /><em>Remarks:</em><br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> Copies the client coordinates of the CWnd client area into the structure pointed to by lpRect. The client coordinates specify the upper-left and lower-right corners of the client area. Since client coordinates are relative to the upper-left corners of the CWnd client area, the coordinates of the upper-left corner are (0,0).</p>
<p><strong>CWnd::GetWindowRect</strong><br />void GetWindowRect( LPRECT lpRect ) const;<br /><em>Parameters:</em><br /><em>lpRect</em><br />Points to a CRect object or a RECT structure that will receive the screen coordinates of the upper-left and lower-right corners.<br /><em><strong>Remarks:</strong></em><br />Copies the dimensions of the bounding rectangle of the CWnd object to the structure pointed to by lpRect. The dimensions are given in screen coordinates relative to the upper-left corner of the display screen. The dimensions of the caption, border, and scroll bars, if present, are included.</p>
<p><font color="#ff0000">GetWindowRect() 得到的是在屏幕坐标系下的RECT；（<font color="#800000">即以屏幕左上角为原点</font>）<br />GetClientRect() 得到的是在客户区坐标系下的RECT； （<font color="#800000">即以所在窗口左上角为原点</font>）<br /><br />GetWindowRect()取的是整个窗口的矩形；<br />GetClientRect()取的仅是客户区的矩形，也就是说不包括标题栏，外框等；</font></p>
<p><font color="#ff0000">第一个函数获得的是窗口在屏幕上的位置，得到的结果可能是这样CRect(10,10,240,240);<br />第二个函数和它不同，它只获得了客户区的大小，因此得到的结果总是这样CRect(0,0,width,height);</font></p>
<p><font color="#ff0000">ScreenToClient() 就是把屏幕坐标系下的RECT坐标转换为客户区坐标系下的RECT坐标。</font></p>
<p><font color="#3366ff"><font color="#0000ff">The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).</font></font></p>
<p><font color="#ff0000">GetClientRect得到的是客户区的大小，也就是说这样得到的左上角永远是（0，0）</font></p>
<p><font color="#0000ff">The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.</font></p>
<p><font color="#ff0000">GetWindowRect 是窗口相对于整个屏幕的坐标，屏幕左上点为0，0</font></p>
<p><font color="#ff0000">相互转化用ScreenToClient 或者 ClientToScreen</font></p>
<p><strong>ClientToScreen</strong><br />The ClientToScreen function converts the client coordinates of a specified point to screen coordinates.<br /><em>BOOL ClientToScreen(<br />&nbsp;<wbr>&nbsp;<wbr> HWND hWnd,&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> // window handle for source coordinates<br />&nbsp;<wbr>&nbsp;<wbr> LPPOINT lpPoint&nbsp;<wbr>&nbsp;<wbr> // pointer to structure containing screen coordinates<br />);</em><br /><em><strong>Parameters</strong></em><br /><em>hWnd</em><br />Handle to the window whose client area is used for the conversion.<br /><em>lpPoint<br /></em>Pointer to a POINT structure that contains the client coordinates to be converted. The new screen coordinates are copied into this structure if the function succeeds.<br /><em><strong>Return Values</strong></em><br />If the function succeeds, the return value is nonzero.<br /><font color="#3366ff"><font color="#000000">If the function fails, the return value is zero.<br /></font></font><font color="#3366ff"><font color="#0000ff">虽然存在调用GetWindowRect后再调用ScreenToClient==GetClientRect，但ScreenToClient（）和ClientToScreen()两者都是属于WINDOWS API函数，可能是存在一定的冗余设计，但意义不同。<br />不过在.Net Framework下对WINDOWS API函数进行了重新整理和优化，在获取控件或窗口的屏幕坐标和客户区坐标时更方便的多，只需要得到与控件或窗口相对应屏幕坐标和客户区坐标属性值就可以了</font>。</font></p><font color="#7c7c7c"><strong>ScreenToClient</strong><br />The ScreenToClient function converts the screen coordinates of a specified point on the screen to client coordinates.<br /></font><font color="#7c7c7c"><em>BOOL ScreenToClient(<br />&nbsp;<wbr>&nbsp;<wbr> HWND hWnd,&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> // window handle for source coordinates<br />&nbsp;<wbr>&nbsp;<wbr> LPPOINT lpPoint&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> // address of structure containing coordinates<br />);<br /></em><em><strong>Parameters：</strong></em><br /></font><font color="#7c7c7c"><em>hWnd<br /></em>Handle to the window whose client area will be used for the conversion.<br /></font><font color="#7c7c7c"><em>lpPoint<br /></em>Pointer to a POINT structure that contains the screen coordinates to be converted.<br /></font><font color="#7c7c7c"><em><strong>Return Values：<br /></strong></em>If the function succeeds, the return value is nonzero.<br />If the function fails, the return value is zero.</font><img src ="http://www.cppblog.com/polly-yang/aggbug/165507.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2012-02-13 20:01 <a href="http://www.cppblog.com/polly-yang/archive/2012/02/13/165507.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>图像编辑</title><link>http://www.cppblog.com/polly-yang/archive/2011/10/28/159258.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Fri, 28 Oct 2011 02:08:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2011/10/28/159258.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/159258.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2011/10/28/159258.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/159258.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/159258.html</trackback:ping><description><![CDATA[<div><div>Pen pen(Color::Black);</div><div><span style="white-space:pre">	</span>int width = abs(m_vecPoint[1].X - m_vecPoint[0].X);</div><div><span style="white-space:pre">	</span>int height = abs(m_vecPoint[1].Y - m_vecPoint[0].Y);</div><div><span style="white-space:pre">	</span>if (width&lt;0||height&lt;0)</div><div><span style="white-space:pre">	</span>{</div><div><span style="white-space:pre">		</span>graphic.DrawRectangle(&amp;pen,m_vecPoint[1].X,m_vecPoint[1].Y,width,height);</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span>else{</div><div><span style="white-space:pre">			</span>graphic.DrawRectangle(&amp;pen,m_vecPoint[0].X,m_vecPoint[0].Y,width,height);</div><div><span style="white-space:pre">	</span>}</div><div><span style="white-space:pre">	</span></div></div><img src ="http://www.cppblog.com/polly-yang/aggbug/159258.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2011-10-28 10:08 <a href="http://www.cppblog.com/polly-yang/archive/2011/10/28/159258.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC之3:在视图中打开图片</title><link>http://www.cppblog.com/polly-yang/archive/2011/05/29/147629.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Sun, 29 May 2011 08:54:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2011/05/29/147629.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/147629.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2011/05/29/147629.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/147629.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/147629.html</trackback:ping><description><![CDATA[<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: #008080">1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #008000">//</span><span style="color: #008000">调用位图,执行程序时打开图片</span><span style="color: #008000"><br /></span><span style="color: #008080">2</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CDC&nbsp;memdc;<br /></span><span style="color: #008080">3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;CBitmap&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">olddc;<br /></span><span style="color: #008080">4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;CBitmap&nbsp;bitmap;<br /></span><span style="color: #008080">5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;bitmap.LoadBitmap(IDB_BITMAP1);<br /></span><span style="color: #008080">6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">=</span><span style="color: #0000ff">this</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetDC();<br /></span><span style="color: #008080">7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;memdc.CreateCompatibleDC(pDC);<br /></span><span style="color: #008080">8</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;olddc</span><span style="color: #000000">=</span><span style="color: #000000">memdc.SelectObject(</span><span style="color: #000000">&amp;</span><span style="color: #000000">bitmap);<br /></span><span style="color: #008080">9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">BitBlt(</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,rect.Width(),rect.Height(),</span><span style="color: #000000">&amp;</span><span style="color: #000000">memdc,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,SRCCOPY);</span></div>当然，先免不了设置坐标系。<img src ="http://www.cppblog.com/polly-yang/aggbug/147629.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2011-05-29 16:54 <a href="http://www.cppblog.com/polly-yang/archive/2011/05/29/147629.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC程序之2：GDI画图入门之 随机点+BitBlt()+CPen</title><link>http://www.cppblog.com/polly-yang/archive/2011/05/26/147303.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Thu, 26 May 2011 14:43:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2011/05/26/147303.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/147303.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2011/05/26/147303.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/147303.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/147303.html</trackback:ping><description><![CDATA[<p><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/polly-yang/33.jpg" width="660" longdesc="" height="678" /><br />核心代码如下</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: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #008000">//</span><span style="color: #008000">&nbsp;TODO:&nbsp;在此处为本机数据添加绘制代码</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CRect&nbsp;rect;<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;GetClientRect(</span><span style="color: #000000">&amp;</span><span style="color: #000000">rect);<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetMapMode(MM_ANISOTROPIC);<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetWindowExt(</span><span style="color: #000000">100</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">100</span><span style="color: #000000">);</span><span style="color: #008000">//</span><span style="color: #008000">窗口逻辑大小：1000*1000,</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetViewportExt(</span><span style="color: #000000">100</span><span style="color: #000000">,&nbsp;</span><span style="color: #000000">-</span><span style="color: #000000">100</span><span style="color: #000000">);</span><span style="color: #008000">//</span><span style="color: #008000">改变Y坐标方向--viewport使用物理大小</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetViewportOrg(rect.left,&nbsp;rect.bottom);</span><span style="color: #008000">//</span><span style="color: #008000">设置窗口中心点为坐标系原点--Viewport使用物理大小&nbsp;</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CPen&nbsp;PenNew(PS_GEOMETRIC,</span><span style="color: #000000">10</span><span style="color: #000000">,RGB(</span><span style="color: #000000">255</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">));<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;CPen</span><span style="color: #000000">*</span><span style="color: #000000">&nbsp;pPenOld;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pPenOld</span><span style="color: #000000">=</span><span style="color: #000000">pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SelectObject(</span><span style="color: #000000">&amp;</span><span style="color: #000000">PenNew);<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img id="Codehighlighter1_417_423_Open_Image" onclick="this.style.display='none'; Codehighlighter1_417_423_Open_Text.style.display='none'; Codehighlighter1_417_423_Closed_Image.style.display='inline'; Codehighlighter1_417_423_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_417_423_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_417_423_Closed_Text.style.display='none'; Codehighlighter1_417_423_Open_Image.style.display='inline'; Codehighlighter1_417_423_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;srand((unsigned)&nbsp;time(NULL));&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_417_423_Closed_Text">/**/</span><span id="Codehighlighter1_417_423_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">播种子</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">MoveTo(</span><span style="color: #000000">50</span><span style="color: #000000">,</span><span style="color: #000000">50</span><span style="color: #000000">);<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">pDC-&gt;LineTo(100,100);</span><span style="color: #008000"><br /></span><span style="color: #008080">15</span><span style="color: #008000"><img id="Codehighlighter1_493_602_Open_Image" onclick="this.style.display='none'; Codehighlighter1_493_602_Open_Text.style.display='none'; Codehighlighter1_493_602_Closed_Image.style.display='inline'; Codehighlighter1_493_602_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_493_602_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_493_602_Closed_Text.style.display='none'; Codehighlighter1_493_602_Open_Image.style.display='inline'; Codehighlighter1_493_602_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">&nbsp;(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">5</span><span style="color: #000000">;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_493_602_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_493_602_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;x</span><span style="color: #000000">=</span><span style="color: #000000">rand()</span><span style="color: #000000">%</span><span style="color: #000000">500</span><span style="color: #000000">;<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;y</span><span style="color: #000000">=</span><span style="color: #000000">rand()</span><span style="color: #000000">%</span><span style="color: #000000">500</span><span style="color: #000000">;<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">LineTo(x,y);<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">BitBlt(x,y,</span><span style="color: #000000">25</span><span style="color: #000000">,</span><span style="color: #000000">25</span><span style="color: #000000">,NULL,</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">0</span><span style="color: #000000">,BLACKNESS);<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;pDC</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SelectObject(pPenOld);<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;PenNew.DeleteObject();</span></div>
<p>：</p> <img src ="http://www.cppblog.com/polly-yang/aggbug/147303.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2011-05-26 22:43 <a href="http://www.cppblog.com/polly-yang/archive/2011/05/26/147303.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC程序之1 个人所得税计算器</title><link>http://www.cppblog.com/polly-yang/archive/2011/05/24/147063.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Tue, 24 May 2011 15:15:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2011/05/24/147063.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/147063.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2011/05/24/147063.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/147063.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/147063.html</trackback:ping><description><![CDATA[<img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/polly-yang/未命名.jpg" width="564" longdesc="" height="383" />
<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: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;&nbsp;Cpaytax2Dlg::OnEnChangeEdit1()<br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img id="Codehighlighter1_37_386_Open_Image" onclick="this.style.display='none'; Codehighlighter1_37_386_Open_Text.style.display='none'; Codehighlighter1_37_386_Closed_Image.style.display='inline'; Codehighlighter1_37_386_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_37_386_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_37_386_Closed_Text.style.display='none'; Codehighlighter1_37_386_Open_Image.style.display='inline'; Codehighlighter1_37_386_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_37_386_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_37_386_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;TODO:&nbsp;&nbsp;如果该控件是&nbsp;RICHEDIT&nbsp;控件，则它将不会<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;发送该通知，除非重写&nbsp;CDialog::OnInitDialog()<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;函数并调用&nbsp;CRichEditCtrl().SetEventMask()，<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;同时将&nbsp;ENM_CHANGE&nbsp;标志&#8220;或&#8221;运算到掩码中。<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;TODO:&nbsp;&nbsp;在此添加控件通知处理程序代码</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CEdit&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">wEdit1;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;wEdit1</span><span style="color: #000000">=</span><span style="color: #000000">(CEdit</span><span style="color: #000000">*</span><span style="color: #000000">)GetDlgItem(IDC_EDIT1);<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">wEdit1-&gt;SetWindowText(&nbsp;"FOO"&nbsp;);<br /></span><span style="color: #008080">12</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">取值</span><span style="color: #008000"><br /></span><span style="color: #008080">13</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;CString&nbsp;str;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(IDC_EDIT1)</span><span style="color: #000000">-&gt;</span><span style="color: #000000">GetWindowText(str);<br /></span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;temp</span><span style="color: #000000">=</span><span style="color: #000000">atof(str);<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;Cpaytax2Dlg::OnBnClickedOk()<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img id="Codehighlighter1_423_749_Open_Image" onclick="this.style.display='none'; Codehighlighter1_423_749_Open_Text.style.display='none'; Codehighlighter1_423_749_Closed_Image.style.display='inline'; Codehighlighter1_423_749_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_423_749_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_423_749_Closed_Text.style.display='none'; Codehighlighter1_423_749_Open_Image.style.display='inline'; Codehighlighter1_423_749_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_423_749_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_423_749_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;TODO:&nbsp;在此添加控件通知处理程序代码</span><span style="color: #008000"><br /></span><span style="color: #008080">21</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;UpdateData(TRUE);<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;PayTax&nbsp;paytax(temp);<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;temp2</span><span style="color: #000000">=</span><span style="color: #000000">paytax.calculate();<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//<br /></span><span style="color: #008080">25</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;UpdateData(FALSE);<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(IDC_EDIT1)</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetFocus();<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;((CEdit&nbsp;</span><span style="color: #000000">*</span><span style="color: #000000">)GetDlgItem(IDC_EDIT1))</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetSel(</span><span style="color: #000000">0</span><span style="color: #000000">,</span><span style="color: #000000">-</span><span style="color: #000000">1</span><span style="color: #000000">,TRUE);<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /><br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;UpdateData(FALSE);<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;CString&nbsp;str;<br /></span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;str.Format(</span><span style="color: #000000">"</span><span style="color: #000000">%f</span><span style="color: #000000">"</span><span style="color: #000000">,temp2);<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;GetDlgItem(IDC_EDIT2)</span><span style="color: #000000">-&gt;</span><span style="color: #000000">SetWindowText(str);&nbsp;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">OnOK();</span><span style="color: #008000"><br /></span><span style="color: #008080">34</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000"><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></div> <img src ="http://www.cppblog.com/polly-yang/aggbug/147063.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2011-05-24 23:15 <a href="http://www.cppblog.com/polly-yang/archive/2011/05/24/147063.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>20110518 linux中IO调度算法小结</title><link>http://www.cppblog.com/polly-yang/archive/2011/05/18/146683.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Wed, 18 May 2011 10:32:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2011/05/18/146683.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/146683.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2011/05/18/146683.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/146683.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/146683.html</trackback:ping><description><![CDATA[<p>在Linux 2.6中,有四种关于IO的调度算法,下面综合小结一下:</p>
<p>1) NOOP </p>
<p>NOOP算法的全写为No Operation。该算法实现了最最简单的FIFO队列，所有IO请求大致按照先来后到的顺序进行操作。之所以说&#8220;大致&#8221;，</p>
<p>原因是NOOP在FIFO的基础上还做了相邻IO请求的合并，并不是完完全全按照先进先出的规则满足IO请求。NOOP假定I/O请求由驱动程序或者设</p>
<p>备做了优化或者重排了顺序(就像一个智能控制器完成的工作那样)。在有些SAN环境下，这个选择可能是最好选择。Noop 对于 IO 不那么操</p>
<p>心，对所有的 IO请求都用 FIFO 队列形式处理，默认认为 IO 不会存在性能问题。这也使得 CPU 也不用那么操心。<a href="http://www.linuxidc.com">www.linuxidc.com</a>当然</p>
<p>，对于复杂一点的应用类型，使用这个调度器，用户自己就会非常操心。 </p>
<p><br />2) Deadline scheduler </p>
<p>DEADLINE在CFQ的基础上，解决了IO请求饿死的极端情况。除了CFQ本身具有的IO排序队列之外，DEADLINE额外分别为读IO和写IO提供了FIFO</p>
<p>队列。读FIFO队列的最大等待时间为500ms，写FIFO队列的最大等待时间为5s。FIFO队列内的IO请求优先级要比CFQ队列中的高，，而读FIFO</p>
<p>队列的优先级又比写FIFO队列的优先级高。优先级可以表示如下： </p>
<p>FIFO(Read) &gt; FIFO(Write) &gt; CFQ </p>
<p>deadline 算法保证对于既定的 IO 请求以最小的延迟时间，从这一点理解，对于 DSS 应用应该会是很适合的。</p>
<p>3) Anticipatory scheduler </p>
<p>CFQ和DEADLINE考虑的焦点在于满足零散IO请求上。对于连续的IO请求，比如顺序读，并没有做优化。为了满足随机IO和顺序IO混合的场景，</p>
<p>Linux还支持ANTICIPATORY调度算法。ANTICIPATORY的在DEADLINE的基础上，为每个读IO都设置了6ms 的等待时间窗口。如果在这6ms内OS收</p>
<p>到了相邻位置的读IO请求，就可以立即满足 </p>
<p>Anticipatory scheduler（as) 曾经一度是 Linux 2.6 Kernel 的 IO scheduler 。Anticipatory 的中文含义是&#8221;预料的, 预想的&#8221;, 这个</p>
<p>词的确揭示了这个算法的特点，简单的说，有个 IO 发生的时候，如果又有进程请求 IO 操作，则将产生一个默认的 6 毫秒猜测时间，猜测</p>
<p>下一个 进程请求 IO 是要干什么的。这对于随即读取会造成比较大的延时，对数据库应用很糟糕，而对于 Web Server 等则会表现的不错。</p>
<p>这个算法也可以简单理解为面向低速磁盘的，因为那个&#8221;猜测&#8221;实际上的目的是为了减少磁头移动时间。</p>
<p>4）CFQ </p>
<p>CFQ算法的全写为Completely Fair Queuing。该算法的特点是按照IO请求的地址进行排序，而不是按照先来后到的顺序来进行响应。 </p>
<p>在传统的SAS盘上，磁盘寻道花去了绝大多数的IO响应时间。CFQ的出发点是对IO地址进行排序，以尽量少的磁盘旋转次数来满足尽可能多的</p>
<p>IO请求。在CFQ算法下，SAS盘的吞吐量大大提高了。但是相比于NOOP的缺点是，先来的IO请求并不一定能被满足，可能会出现饿死的情况。 </p>
<p>Completely Fair Queuing （cfq, 完全公平队列) 在 2.6.18 取代了 Anticipatory scheduler 成为 Linux Kernel 默认的 IO scheduler </p>
<p>。cfq 对每个进程维护一个 IO 队列，各个进程发来的 IO 请求会被 cfq 以轮循方式处理。也就是对每一个 IO 请求都是公平的。这使得 </p>
<p>cfq 很适合离散读的应用(eg: OLTP DB)。我所知道的企业级 Linux 发行版中，SUSE Linux 好像是最先默认用 cfq 的.</p>
<p>查看和修改IO调度器的算法非常简单。假设我们要对sda进行操作，如下所示： </p>
<p>cat /sys/block/sda/queue/scheduler </p>
<p>echo &#8220;cfq&#8221; &gt; /sys/block/sda/queue/scheduler</p>
<p>总结: </p>
<p>1 CFQ和DEADLINE考虑的焦点在于满足零散IO请求上。对于连续的IO请求，比如顺序读，并没有做优化。为了满足随机IO和顺序IO混合的场景</p>
<p>，Linux还支持ANTICIPATORY调度算法。ANTICIPATORY的在DEADLINE的基础上，为每个读IO都设置了6ms的等待时间窗口。如果在这6ms内OS收</p>
<p>到了相邻位置的读IO请求，就可以立即满足。</p>
<p>IO调度器算法的选择，既取决于硬件特征，也取决于应用场景。 </p>
<p>在传统的SAS盘上，CFQ、DEADLINE、ANTICIPATORY都是不错的选择；对于专属的数据库服务器，DEADLINE的吞吐量和响应时间都表现良好。</p>
<p>然而在新兴的固态硬盘比如SSD、Fusion IO上，最简单的NOOP反而可能是最好的算法，因为其他三个算法的优化是基于缩短寻道时间的，而</p>
<p>固态硬盘没有所谓的寻道时间且IO响应时间非常短。</p>
<p>2 对于数据库应用, Anticipatory Scheduler 的表现是最差的。Deadline 在 DSS 环境表现比 cfq 更好一点，而 cfq 综合来看表现更好一</p>
<p>些。这也难怪 RHEL 4 默认的 IO 调度器设置为 cfq. 而 RHEL 4 比 RHEL 3，整体 IO 改进还是不小的。 </p>
<p>&nbsp;</p><img src ="http://www.cppblog.com/polly-yang/aggbug/146683.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2011-05-18 18:32 <a href="http://www.cppblog.com/polly-yang/archive/2011/05/18/146683.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>20110518 模式识别-近邻聚类算法</title><link>http://www.cppblog.com/polly-yang/archive/2011/05/18/146626.html</link><dc:creator>polly</dc:creator><author>polly</author><pubDate>Wed, 18 May 2011 02:26:00 GMT</pubDate><guid>http://www.cppblog.com/polly-yang/archive/2011/05/18/146626.html</guid><wfw:comment>http://www.cppblog.com/polly-yang/comments/146626.html</wfw:comment><comments>http://www.cppblog.com/polly-yang/archive/2011/05/18/146626.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/polly-yang/comments/commentRss/146626.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/polly-yang/services/trackbacks/146626.html</trackback:ping><description><![CDATA[<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"><img id="Code_Closed_Image_102450" onclick="this.style.display='none'; Code_Closed_Text_102450.style.display='none'; Code_Open_Image_102450.style.display='inline'; Code_Open_Text_102450.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" width="11" height="16"><img style="display: none" id="Code_Open_Image_102450" onclick="this.style.display='none'; Code_Open_Text_102450.style.display='none'; Code_Closed_Image_102450.style.display='inline'; Code_Closed_Text_102450.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" width="11" height="16"><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Code_Closed_Text_102450"></span><span style="display: none" id="Code_Open_Text_102450"><br /><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008080">&nbsp;1</span><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #008000">//</span><span style="color: #008000">近邻聚类法&nbsp;20110517<br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #008000">//</span><span style="color: #008000">20110518</span><span style="color: #008000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdio.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">math.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">stdlib.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">time.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">#define</span><span style="color: #000000">&nbsp;MAX&nbsp;10</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img id="Codehighlighter1_130_183_Open_Image" onclick="this.style.display='none'; Codehighlighter1_130_183_Open_Text.style.display='none'; Codehighlighter1_130_183_Closed_Image.style.display='inline'; Codehighlighter1_130_183_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_130_183_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_130_183_Closed_Text.style.display='none'; Codehighlighter1_130_183_Open_Image.style.display='inline'; Codehighlighter1_130_183_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">struct</span><span style="color: #000000">&nbsp;point</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_130_183_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_130_183_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;x;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;y;<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;flag;<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000">;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />point&nbsp;p[MAX];<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #008000">//</span><span style="color: #008000">point&nbsp;z[MAX];</span><span style="color: #008000"><br /></span><span style="color: #008080">15</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;T</span><span style="color: #000000">=</span><span style="color: #000000">5</span><span style="color: #000000">;<br /></span><span style="color: #008080">16</span><span style="color: #000000"><img id="Codehighlighter1_244_473_Open_Image" onclick="this.style.display='none'; Codehighlighter1_244_473_Open_Text.style.display='none'; Codehighlighter1_244_473_Closed_Image.style.display='inline'; Codehighlighter1_244_473_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_244_473_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_244_473_Closed_Text.style.display='none'; Codehighlighter1_244_473_Open_Image.style.display='inline'; Codehighlighter1_244_473_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;randpoint()</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_244_473_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_244_473_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;srand((unsigned)time(NULL));<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img id="Codehighlighter1_307_466_Open_Image" onclick="this.style.display='none'; Codehighlighter1_307_466_Open_Text.style.display='none'; Codehighlighter1_307_466_Closed_Image.style.display='inline'; Codehighlighter1_307_466_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_307_466_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_307_466_Closed_Text.style.display='none'; Codehighlighter1_307_466_Open_Image.style.display='inline'; Codehighlighter1_307_466_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">MAX;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_307_466_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_307_466_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p[i].x</span><span style="color: #000000">=</span><span style="color: #000000">(rand()</span><span style="color: #000000">%</span><span style="color: #000000">100</span><span style="color: #000000">)</span><span style="color: #000000">/</span><span style="color: #000000">10.0</span><span style="color: #000000">;<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p[i].y</span><span style="color: #000000">=</span><span style="color: #000000">(rand()</span><span style="color: #000000">%</span><span style="color: #000000">100</span><span style="color: #000000">)</span><span style="color: #000000">/</span><span style="color: #000000">10.0</span><span style="color: #000000">;<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p[i].flag</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">z[i].flag=0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000"><br /></span><span style="color: #008080">24</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">26</span><span style="color: #000000"><img id="Codehighlighter1_489_608_Open_Image" onclick="this.style.display='none'; Codehighlighter1_489_608_Open_Text.style.display='none'; Codehighlighter1_489_608_Closed_Image.style.display='inline'; Codehighlighter1_489_608_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_489_608_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_489_608_Closed_Text.style.display='none'; Codehighlighter1_489_608_Open_Image.style.display='inline'; Codehighlighter1_489_608_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;display()</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_489_608_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_489_608_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img id="Codehighlighter1_518_606_Open_Image" onclick="this.style.display='none'; Codehighlighter1_518_606_Open_Text.style.display='none'; Codehighlighter1_518_606_Closed_Image.style.display='inline'; Codehighlighter1_518_606_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_518_606_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_518_606_Closed_Text.style.display='none'; Codehighlighter1_518_606_Open_Image.style.display='inline'; Codehighlighter1_518_606_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">MAX;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_518_606_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_518_606_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">28</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(</span><span style="color: #000000">"</span><span style="color: #000000">%8.2f&nbsp;%8.2f----%d\n</span><span style="color: #000000">"</span><span style="color: #000000">,p[i].x,p[i].y,p[i].flag);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">31</span><span style="color: #000000"><img id="Codehighlighter1_639_717_Open_Image" onclick="this.style.display='none'; Codehighlighter1_639_717_Open_Text.style.display='none'; Codehighlighter1_639_717_Closed_Image.style.display='inline'; Codehighlighter1_639_717_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_639_717_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_639_717_Closed_Text.style.display='none'; Codehighlighter1_639_717_Open_Image.style.display='inline'; Codehighlighter1_639_717_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;dis(point&nbsp;p1,point&nbsp;p2)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_639_717_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_639_717_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;sqrt((p1.x</span><span style="color: #000000">-</span><span style="color: #000000">p2.x)</span><span style="color: #000000">*</span><span style="color: #000000">(p1.x</span><span style="color: #000000">-</span><span style="color: #000000">p2.x)</span><span style="color: #000000">+</span><span style="color: #000000">(p1.y</span><span style="color: #000000">-</span><span style="color: #000000">p2.y)</span><span style="color: #000000">*</span><span style="color: #000000">(p1.y</span><span style="color: #000000">-</span><span style="color: #000000">p2.y));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /></span><span style="color: #008080">35</span><span style="color: #000000"><img id="Codehighlighter1_730_1602_Open_Image" onclick="this.style.display='none'; Codehighlighter1_730_1602_Open_Text.style.display='none'; Codehighlighter1_730_1602_Closed_Image.style.display='inline'; Codehighlighter1_730_1602_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_730_1602_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_730_1602_Closed_Text.style.display='none'; Codehighlighter1_730_1602_Open_Image.style.display='inline'; Codehighlighter1_730_1602_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_730_1602_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_730_1602_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">z[0].x=p[0].x;<br /></span><span style="color: #008080">37</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">z[0].y=p[0].y;</span><span style="color: #008000"><br /></span><span style="color: #008080">38</span><span style="color: #008000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;randpoint();&nbsp;<br /></span><span style="color: #008080">39</span><span style="color: #000000"><img id="Codehighlighter1_834_1554_Open_Image" onclick="this.style.display='none'; Codehighlighter1_834_1554_Open_Text.style.display='none'; Codehighlighter1_834_1554_Closed_Image.style.display='inline'; Codehighlighter1_834_1554_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_834_1554_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_834_1554_Closed_Text.style.display='none'; Codehighlighter1_834_1554_Open_Image.style.display='inline'; Codehighlighter1_834_1554_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;i</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;i</span><span style="color: #000000">&lt;</span><span style="color: #000000">MAX;i</span><span style="color: #000000">++</span><span style="color: #000000">)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_834_1554_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_834_1554_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;imin</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;;<br /></span><span style="color: #008080">41</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;mindistance</span><span style="color: #000000">=</span><span style="color: #000000">dis(p[i],p[</span><span style="color: #000000">0</span><span style="color: #000000">]);<br /></span><span style="color: #008080">42</span><span style="color: #000000"><img id="Codehighlighter1_966_1343_Open_Image" onclick="this.style.display='none'; Codehighlighter1_966_1343_Open_Text.style.display='none'; Codehighlighter1_966_1343_Closed_Image.style.display='inline'; Codehighlighter1_966_1343_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_966_1343_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_966_1343_Closed_Text.style.display='none'; Codehighlighter1_966_1343_Open_Image.style.display='inline'; Codehighlighter1_966_1343_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">for</span><span style="color: #000000">(</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">=</span><span style="color: #000000">0</span><span style="color: #000000">;p[j].flag</span><span style="color: #000000">==</span><span style="color: #000000">j</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">j</span><span style="color: #000000">&lt;</span><span style="color: #000000">MAX;)&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_966_1343_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_966_1343_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">double</span><span style="color: #000000">&nbsp;tempdistance</span><span style="color: #000000">=</span><span style="color: #000000">dis(p[i],p[j]);<br /></span><span style="color: #008080">44</span><span style="color: #000000"><img id="Codehighlighter1_1080_1259_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1080_1259_Open_Text.style.display='none'; Codehighlighter1_1080_1259_Closed_Image.style.display='inline'; Codehighlighter1_1080_1259_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1080_1259_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1080_1259_Closed_Text.style.display='none'; Codehighlighter1_1080_1259_Open_Image.style.display='inline'; Codehighlighter1_1080_1259_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(mindistance</span><span style="color: #000000">&gt;</span><span style="color: #000000">tempdistance)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1080_1259_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1080_1259_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">45</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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;mindistance</span><span style="color: #000000">=</span><span style="color: #000000">tempdistance;<br /></span><span style="color: #008080">46</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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;imin</span><span style="color: #000000">=</span><span style="color: #000000">j;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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;j</span><span style="color: #000000">++</span><span style="color: #000000">;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">48</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">49</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;j</span><span style="color: #000000">++</span><span style="color: #000000">;<br /></span><span style="color: #008080">50</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">51</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">52</span><span style="color: #000000"><img id="Codehighlighter1_1380_1456_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1380_1456_Open_Text.style.display='none'; Codehighlighter1_1380_1456_Closed_Image.style.display='inline'; Codehighlighter1_1380_1456_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1380_1456_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1380_1456_Closed_Text.style.display='none'; Codehighlighter1_1380_1456_Open_Image.style.display='inline'; Codehighlighter1_1380_1456_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">(mindistance&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;T)</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1380_1456_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1380_1456_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">53</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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;p[i].flag</span><span style="color: #000000">=</span><span style="color: #000000">i;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">54</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">55</span><span style="color: #000000"><img id="Codehighlighter1_1478_1542_Open_Image" onclick="this.style.display='none'; Codehighlighter1_1478_1542_Open_Text.style.display='none'; Codehighlighter1_1478_1542_Closed_Image.style.display='inline'; Codehighlighter1_1478_1542_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_1478_1542_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_1478_1542_Closed_Text.style.display='none'; Codehighlighter1_1478_1542_Open_Image.style.display='inline'; Codehighlighter1_1478_1542_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">else</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_1478_1542_Closed_Text"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_1478_1542_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">56</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p[i].flag</span><span style="color: #000000">=</span><span style="color: #000000">imin;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #008080">57</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000">&nbsp;&nbsp;<br /></span><span style="color: #008080">58</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">59</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display();<br /></span><span style="color: #008080">60</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;system(</span><span style="color: #000000">"</span><span style="color: #000000">pause</span><span style="color: #000000">"</span><span style="color: #000000">);&nbsp;&nbsp;<br /></span><span style="color: #008080">61</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif"  alt="" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">62</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span></span></div>教材上的算法根本就没讲明白，琢磨了好久。其实分类效果很不好。数据分析sample如下：<br />&nbsp;&nbsp;&nbsp; 3.20&nbsp;&nbsp;&nbsp;&nbsp; 2.00----0<br />&nbsp;&nbsp;&nbsp; 4.60&nbsp;&nbsp;&nbsp;&nbsp; 5.70----0<br />&nbsp;&nbsp;&nbsp; 1.50&nbsp;&nbsp;&nbsp;&nbsp; 5.00----0<br />&nbsp;&nbsp;&nbsp; 1.80&nbsp;&nbsp;&nbsp;&nbsp; 6.90----3<br />&nbsp;&nbsp;&nbsp; 6.10&nbsp;&nbsp;&nbsp;&nbsp; 5.50----0<br />&nbsp;&nbsp;&nbsp; 7.40&nbsp;&nbsp;&nbsp;&nbsp; 4.90----5<br />&nbsp;&nbsp;&nbsp; 7.20&nbsp;&nbsp;&nbsp;&nbsp; 9.30----6<br />&nbsp;&nbsp;&nbsp; 8.40&nbsp;&nbsp;&nbsp;&nbsp; 0.40----7<br />&nbsp;&nbsp;&nbsp; 9.00&nbsp;&nbsp;&nbsp;&nbsp; 2.70----8<br />&nbsp;&nbsp;&nbsp; 4.30&nbsp;&nbsp;&nbsp;&nbsp; 1.20----0<br /> <img src ="http://www.cppblog.com/polly-yang/aggbug/146626.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/polly-yang/" target="_blank">polly</a> 2011-05-18 10:26 <a href="http://www.cppblog.com/polly-yang/archive/2011/05/18/146626.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>