﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-寒月-随笔分类-其它</title><link>http://www.cppblog.com/wuxu/category/18393.html</link><description /><language>zh-cn</language><lastBuildDate>Sun, 20 Apr 2014 11:06:53 GMT</lastBuildDate><pubDate>Sun, 20 Apr 2014 11:06:53 GMT</pubDate><ttl>60</ttl><item><title>如何在C/C++中动态分配二维数组【转载】</title><link>http://www.cppblog.com/wuxu/archive/2014/04/14/206583.html</link><dc:creator>wuxu</dc:creator><author>wuxu</author><pubDate>Mon, 14 Apr 2014 13:37:00 GMT</pubDate><guid>http://www.cppblog.com/wuxu/archive/2014/04/14/206583.html</guid><wfw:comment>http://www.cppblog.com/wuxu/comments/206583.html</wfw:comment><comments>http://www.cppblog.com/wuxu/archive/2014/04/14/206583.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wuxu/comments/commentRss/206583.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wuxu/services/trackbacks/206583.html</trackback:ping><description><![CDATA[<div><span style="font-size:16px;">原文地址：<a href="http://blog.csdn.net/morewindows/article/details/7664479">http://blog.csdn.net/morewindows/article/details/7664479</a></span></div><br /><div><p><span style="font-size:18px;">在<span style="font-family:Times New Roman;">C/C++</span>中动态分配二维数组可以先申请一维的指针数组，然后该数组中的每个指针再申请数组，这样就相当于二维数组了，但是这种方法会导致每行可能不相邻，从而访问效率比较低。如何申请连续的二维数组了？本文将分别三个方面讲解：</span></p><p><span style="font-size:18px;">一．动态申请列大小固定的二维数组</span></p><p><span style="font-size:18px;">二．<span style="font-family:Times New Roman;">C</span>语言中动态申请连续的二维数组</span></p><p><span style="font-size:18px;">三．<span style="font-family:Times New Roman;">C++</span>语言中动态申请连续的二维数组</span></p><p>&nbsp;</p><h2>一．动态申请列大小固定的二维数组</h2><p><span style="font-size:18px;">首先如果二维数组的列大小固定，那么很简单，可以用申请一维数数组再其指针强制转化成为二维数组指针即可。详见代码：</span></p><div bg_cpp"=""><ol start="1"><li><span>//列大小固定的二维数组可以申请一维数据并将指针强转成二维数组&nbsp;&nbsp;</span></li><li><span>#include&nbsp;&lt;stdio.h&gt;&nbsp;&nbsp;</span></li><li><span>int&nbsp;main()&nbsp;&nbsp;</span></li><li>{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"&nbsp;&nbsp;列大小固定的二维数组可以申请一维数据并将指针强转成二维数组\n");&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"&nbsp;--&nbsp;by&nbsp;MoreWindows(&nbsp;http://blog.csdn.net/MoreWindows&nbsp;)&nbsp;--\n\n");&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//列值固定&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>const&nbsp;int&nbsp;MAXCOL&nbsp;=&nbsp;3;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;nRow;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"请输入二维数组的行数(列值固定为%d):&nbsp;",&nbsp;MAXCOL);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;scanf(<span>"%d",&nbsp;&amp;nRow);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//申请一维数据并将其转成二维数组指针&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;*pp_arr&nbsp;=&nbsp;new&nbsp;int[nRow&nbsp;*&nbsp;MAXCOL];&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;(*p)[MAXCOL]&nbsp;=&nbsp;(int(*)[MAXCOL])pp_arr;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//为二维数组赋值&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;i,&nbsp;j;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;nRow;&nbsp;i++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;MAXCOL;&nbsp;j++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p[i][j]&nbsp;=&nbsp;i&nbsp;+&nbsp;j;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//输出二维数组&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;nRow;&nbsp;i++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;MAXCOL;&nbsp;j++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"%5d",&nbsp;p[i][j]);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;putchar(<span>'\n');&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//释放资源&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>delete[]&nbsp;pp_arr;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>return&nbsp;0;&nbsp;&nbsp;</span></li><li>}&nbsp;&nbsp;</li></ol></div><p><span style="font-size:18px;color:black;">运行结果如下所示：</span></p><p><img alt="" src="http://my.csdn.net/uploads/201206/13/1339577619_1663.PNG" /></p><p>&nbsp;</p><h2>二．C语言中动态申请连续的二维数组</h2><p><span style="font-size:18px;">上面的方法虽然方便，但必须要求列的大小固定。下面先来试下在<span style="font-family:Times New Roman;">C</span>语言中如何动态申请连续的二维数组。可以采用多申请一些指针，然后这一些指针分别指向后面数据区中对应的位置，如一个<span style="font-family:Times New Roman;">3*4</span>的<span style="font-family:Times New Roman;">int</span>类型数组，我们先申请大小为<span style="font-family:Times New Roman;">sizeof(int*) * 3 + 3 * 4 * sizeof(int)</span>的一维数组设为<span style="font-family:Times New Roman;">arr</span>。然后<span style="font-family:Times New Roman;">arr[0]</span>存放指向<span style="font-family:Times New Roman;">arr + sizeof(int*) * 3</span>这个位置的指针，<span style="font-family:Times New Roman;">arr[1]</span>存放指向<span style="font-family:Times New Roman;">arr + sizeof(int*) * 3 + 4 * sizeof(int)</span>这个位置的指针，<span style="font-family:Times New Roman;"> arr[2]</span>存放指向<span style="font-family:Times New Roman;">arr + sizeof(int*) * 3 + 2 * 4 * sizeof(int)</span>这个位置的指针。下面用图展示指向的示意：</span></p><p><span style="font-size:18px;"><img alt="" src="http://my.csdn.net/uploads/201206/13/1339577657_5620.PNG" height="166" width="741" /></span></p><p><span style="font-size:18px;">详细代码如下，由于指针操作有点小复杂，请读者耐心看：</span></p><div bg_cpp"=""><ol start="1"><li><span>//C语言中动态的申请二维数组&nbsp;malloc&nbsp;free&nbsp;&nbsp;</span></li><li><span>#include&nbsp;&lt;stdio.h&gt;&nbsp;&nbsp;</span></li><li><span>#include&nbsp;&lt;stdlib.h&gt;&nbsp;&nbsp;</span></li><li><span>#include&nbsp;&lt;string.h&gt;&nbsp;&nbsp;</span></li><li><span>//动态申请二维数组&nbsp;&nbsp;</span></li><li><span>template&nbsp;&lt;typename&nbsp;T&gt;&nbsp;&nbsp;</span></li><li>T**&nbsp;malloc_Array2D(<span>int&nbsp;row,&nbsp;int&nbsp;col)&nbsp;&nbsp;</span></li><li>{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;size&nbsp;=&nbsp;sizeof(T);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;point_size&nbsp;=&nbsp;sizeof(T*);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//先申请内存，其中point_size&nbsp;*&nbsp;row表示存放row个行指针&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;**arr&nbsp;=&nbsp;(T&nbsp;**)&nbsp;malloc(point_size&nbsp;*&nbsp;row&nbsp;+&nbsp;size&nbsp;*&nbsp;row&nbsp;*&nbsp;col);&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>if&nbsp;(arr&nbsp;!=&nbsp;NULL)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memset(arr,&nbsp;0,&nbsp;point_size&nbsp;*&nbsp;row&nbsp;+&nbsp;size&nbsp;*&nbsp;row&nbsp;*&nbsp;col);&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;*head&nbsp;=&nbsp;(T*)((<span>int)arr&nbsp;+&nbsp;point_size&nbsp;*&nbsp;row);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>while&nbsp;(row--)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr[row]&nbsp;=&nbsp;(T*)((<span>int)head&nbsp;+&nbsp;row&nbsp;*&nbsp;col&nbsp;*&nbsp;size);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>return&nbsp;(T**)arr;&nbsp;&nbsp;</span></li><li>}&nbsp;&nbsp;</li><li><span>//释放二维数组&nbsp;&nbsp;</span></li><li><span>void&nbsp;free_Aarray2D(void&nbsp;**arr)&nbsp;&nbsp;</span></li><li>{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>if&nbsp;(arr&nbsp;!=&nbsp;NULL)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;free(arr);&nbsp;&nbsp;</li><li>}&nbsp;&nbsp;</li><li><span>int&nbsp;main()&nbsp;&nbsp;</span></li><li>{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"&nbsp;&nbsp;C语言中动态的申请二维数组&nbsp;malloc&nbsp;free\n");&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"&nbsp;--&nbsp;by&nbsp;MoreWindows(&nbsp;http://blog.csdn.net/MoreWindows&nbsp;)&nbsp;--\n\n");&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"请输入行列(以空格分开):&nbsp;");&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;nRow,&nbsp;nCol;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;scanf(<span>"%d&nbsp;%d",&nbsp;&amp;nRow,&nbsp;&amp;nCol);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//动态申请连续的二维数组&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;**p&nbsp;=&nbsp;malloc_Array2D&lt;int&gt;(nRow,&nbsp;nCol);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//为二维数组赋值&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;i,&nbsp;j;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;nRow;&nbsp;i++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;nCol;&nbsp;j++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p[i][j]&nbsp;=&nbsp;i&nbsp;+&nbsp;j;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//输出二维数组&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;nRow;&nbsp;i++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;nCol;&nbsp;j++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"%4d&nbsp;",&nbsp;p[i][j]);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;putchar(<span>'\n');&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;free_Aarray2D((<span>void**)p);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>return&nbsp;0;&nbsp;&nbsp;</span></li><li>}&nbsp;&nbsp;</li></ol></div><p><span style="font-size:18px;color:black;">运行结果如下：</span></p><p><img alt="" src="http://my.csdn.net/uploads/201206/13/1339577816_2134.PNG" />&nbsp;</p><p>&nbsp;</p><h2>三．C++语言中动态申请连续的二维数组</h2><p><span style="font-size:18px;">可 以看出我们已经成功实现了在C语言中动态申请连续的二维数组，如果上面的程序不使用int类型而使用string类这种类型，那会有什么后果了？肯定的 说，由于没有调用构造函数和析构函数，程序绝对会造成内存泄露。因此要做下改进，下面给出在C++语言中动态申请连续的二维数组的代码，有些C++语法可 能平时见得少，但其实这些语法在STL里面运用还是比较多的，有兴趣的童鞋应该掌握下。</span></p><div bg_cpp"=""><ol start="1"><li><span>//C++语言中动态的申请二维数组&nbsp;new&nbsp;delete&nbsp;&nbsp;</span></li><li><span>#include&nbsp;&lt;new&gt;&nbsp;&nbsp;</span></li><li><span>#include&nbsp;&lt;cstdio&gt;&nbsp;&nbsp;</span></li><li><span>#include&nbsp;&lt;cstdlib&gt;&nbsp;&nbsp;</span></li><li><span>#include&nbsp;&lt;string&gt;&nbsp;&nbsp;</span></li><li><span>using&nbsp;namespace&nbsp;std;&nbsp;&nbsp;</span></li><li><span>//动态申请二维数组&nbsp;&nbsp;</span></li><li><span>template&nbsp;&lt;typename&nbsp;T&gt;&nbsp;&nbsp;</span></li><li>T**&nbsp;new_Array2D(<span>int&nbsp;row,&nbsp;int&nbsp;col)&nbsp;&nbsp;</span></li><li>{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;size&nbsp;=&nbsp;sizeof(T);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;point_size&nbsp;=&nbsp;sizeof(T*);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//先申请内存，其中sizeof(T*)&nbsp;*&nbsp;row表示存放row个行指针&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;**arr&nbsp;=&nbsp;(T&nbsp;**)&nbsp;malloc(point_size&nbsp;*&nbsp;row&nbsp;+&nbsp;size&nbsp;*&nbsp;row&nbsp;*&nbsp;col);&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>if&nbsp;(arr&nbsp;!=&nbsp;NULL)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;T&nbsp;*head&nbsp;=&nbsp;(T*)((<span>int)arr&nbsp;+&nbsp;point_size&nbsp;*&nbsp;row);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;row;&nbsp;++i)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr[i]&nbsp;=&nbsp;&nbsp;(T*)((<span>int)head&nbsp;+&nbsp;i&nbsp;*&nbsp;col&nbsp;*&nbsp;size);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(int&nbsp;j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;col;&nbsp;++j)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>new&nbsp;(&amp;arr[i][j])&nbsp;T;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>return&nbsp;(T**)arr;&nbsp;&nbsp;</span></li><li>}&nbsp;&nbsp;</li><li><span>//释放二维数组&nbsp;&nbsp;</span></li><li><span>template&nbsp;&lt;typename&nbsp;T&gt;&nbsp;&nbsp;</span></li><li><span>void&nbsp;delete_Array2D(T&nbsp;**arr,&nbsp;int&nbsp;row,&nbsp;int&nbsp;col)&nbsp;&nbsp;</span></li><li>{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;row;&nbsp;++i)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(int&nbsp;j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;col;&nbsp;++j)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr[i][j].~T();&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>if&nbsp;(arr&nbsp;!=&nbsp;NULL)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;free((<span>void**)arr);&nbsp;&nbsp;</span></li><li>}&nbsp;&nbsp;</li><li><span>int&nbsp;main()&nbsp;&nbsp;</span></li><li>{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"&nbsp;&nbsp;C++语言中动态的申请二维数组&nbsp;new&nbsp;delete\n");&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"&nbsp;--&nbsp;by&nbsp;MoreWindows(&nbsp;http://blog.csdn.net/MoreWindows&nbsp;)&nbsp;--\n\n");&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"请输入行列(以空格分开):&nbsp;");&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;nRow,&nbsp;nCol;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;scanf(<span>"%d&nbsp;%d",&nbsp;&amp;nRow,&nbsp;&amp;nCol);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//动态申请连续的二维数组&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;string&nbsp;**p&nbsp;=&nbsp;new_Array2D&lt;string&gt;(nRow,&nbsp;nCol);&nbsp;&nbsp;</li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//为二维数组赋值&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;i,&nbsp;j;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;nRow;&nbsp;i++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;nCol;&nbsp;j++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>char&nbsp;szTemp[30];&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(szTemp,&nbsp;<span>"(第%d行,第%d列)",&nbsp;i,&nbsp;j);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p[i][j]&nbsp;=&nbsp;szTemp;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>//输出二维数组&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(i&nbsp;=&nbsp;0;&nbsp;i&nbsp;&lt;&nbsp;nRow;&nbsp;i++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>for&nbsp;(j&nbsp;=&nbsp;0;&nbsp;j&nbsp;&lt;&nbsp;nCol;&nbsp;j++)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"%s&nbsp;",&nbsp;p[i][j].c_str());&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;putchar(<span>'\n');&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;delete_Array2D&lt;string&gt;(p,&nbsp;nRow,&nbsp;nCol);&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>return&nbsp;0;&nbsp;&nbsp;</span></li><li>}&nbsp;&nbsp;</li></ol></div><p><span style="font-size:18px;">运行结果如下：</span></p><p><img alt="" src="http://my.csdn.net/uploads/201206/13/1339577831_2249.PNG" /></p><p>&nbsp;</p></div><img src ="http://www.cppblog.com/wuxu/aggbug/206583.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wuxu/" target="_blank">wuxu</a> 2014-04-14 21:37 <a href="http://www.cppblog.com/wuxu/archive/2014/04/14/206583.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> Ubuntu 12.04 LTS安装VMware Tools无法找到kernel header path的问题 （转）</title><link>http://www.cppblog.com/wuxu/archive/2013/10/25/203913.html</link><dc:creator>wuxu</dc:creator><author>wuxu</author><pubDate>Fri, 25 Oct 2013 07:58:00 GMT</pubDate><guid>http://www.cppblog.com/wuxu/archive/2013/10/25/203913.html</guid><wfw:comment>http://www.cppblog.com/wuxu/comments/203913.html</wfw:comment><comments>http://www.cppblog.com/wuxu/archive/2013/10/25/203913.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wuxu/comments/commentRss/203913.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wuxu/services/trackbacks/203913.html</trackback:ping><description><![CDATA[Ubuntu 12.04 安装 VMware Tools，运行vmware-config-tools.pl 时，总是提示<br /> The path "" is not valid.<br /> What is the location of the directory of C header files that match your running<br /> kernel?<br /> <p>输入 /usr/src/linux-headers-3.8.0-29-generic/include <br /> </p> <p>或 /lib/modules/3.8.0-26-generic/build/include 都提示&#8220;The path ...&nbsp; is not valid.&#8221;。</p> &nbsp;<br /> 用了半天时间才找到解决方案 555....分享一下。<br /> &nbsp;<br /> 1. 更新或安装linux headers<br /> <p>sudo apt-get update <br /> </p> <p>sudo apt-get install build-essential <br /> </p> <p>sudo apt-get install linux-headers-$(uname -r)</p> &nbsp;<br /> <p>2. 关联文件，就是因为找不到这个几个文件，vmware tools才认为路径无效的。</p> <p>cd /lib/modules/$(uname -r)/build/include/linux</p> <p>sudo ln -s ../generated/utsrelease.h</p> sudo ln -s ../generated/autoconf.h<br /> <p><span style="color:#FF0000">sudo ln -s ../generated/uapi/linux/version.h</span></p> <p><span style="color:#FF0000">就是因为没有最后这个链接，一直失败，郁闷啊。</span><br /> </p> &nbsp;<br /> <p>3. 再次执行安装就ok啦，运行vmware-config-tools.pl 也没问题了。</p> sudo ./vmware-install.pl<img src ="http://www.cppblog.com/wuxu/aggbug/203913.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wuxu/" target="_blank">wuxu</a> 2013-10-25 15:58 <a href="http://www.cppblog.com/wuxu/archive/2013/10/25/203913.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>QT4+MinGW+CodeBlocks 中添加Q_OBJECT宏引起"undefined reference to 'vtable for XXX' "的问题解决方法</title><link>http://www.cppblog.com/wuxu/archive/2011/12/22/162596.html</link><dc:creator>wuxu</dc:creator><author>wuxu</author><pubDate>Thu, 22 Dec 2011 06:54:00 GMT</pubDate><guid>http://www.cppblog.com/wuxu/archive/2011/12/22/162596.html</guid><wfw:comment>http://www.cppblog.com/wuxu/comments/162596.html</wfw:comment><comments>http://www.cppblog.com/wuxu/archive/2011/12/22/162596.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wuxu/comments/commentRss/162596.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wuxu/services/trackbacks/162596.html</trackback:ping><description><![CDATA[&nbsp;<span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">首先，确定已经使用</span><span lang="EN-US">Tools &gt; Configure tools...</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">配置好了两个工具：</span><span lang="EN-US">qmake &#8211;pro, qmake</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">。</span> 
<p style="line-height: 150%; text-indent: 89.25pt; mso-char-indent-count: 8.5" class="MsoNormal"><span lang="EN-US"><o:p><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/wuxu/未命名.jpg" width="276" height="117" />&nbsp;</o:p></span></p>
<p style="line-height: 150%" class="MsoNormal"><span lang="EN-US">qmake &#8211;pro </span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">配置如下：<br /></span></p>
<p style="line-height: 150%" class="MsoNormal"><span style="mso-no-proof: yes" lang="EN-US"></span></p>
<p style="line-height: 150%" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin"><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/wuxu/g.jpg" width="564" height="273" /><br />注意：</span><span lang="EN-US">&#8220;-project&#8221;</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">前有个空格。</span></p>
<p style="line-height: 150%" class="MsoNormal"><span lang="EN-US"><o:p></o:p></span></p>
<p style="line-height: 150%" class="MsoNormal"><span lang="EN-US">qmake </span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">配置如下：</span></p>
<p style="line-height: 150%" class="MsoNormal"><span style="mso-no-proof: yes" lang="EN-US"></span></p>
<p style="line-height: 150%" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin"><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/wuxu/v.jpg" width="564" height="274" /><br /><br />其次，在创建工程时，把输出文件目录中的</span><span lang="EN-US">bin</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">（和</span><span lang="EN-US">obj</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">）都去掉，直接用</span><span lang="EN-US">Debug</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">和</span><span lang="EN-US">Release</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">作为输出目录，如下图。（该步骤为可选）</span><span lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><strong style="mso-bidi-font-weight: normal">[</strong></span><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; mso-ascii-theme-font: minor-fareast; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-fareast">&#9733;</span><span lang="EN-US">]</span></strong></p>
<p style="line-height: 150%" class="MsoNormal"><span style="mso-no-proof: yes" lang="EN-US"></span></p>
<p style="line-height: 150%" class="MsoNormal"><span lang="EN-US"><o:p><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/wuxu/j.jpg" width="558" height="439" />&nbsp;</o:p></span></p>
<p style="line-height: 150%" class="MsoNormal"><span lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="line-height: 150%; text-indent: -18pt; margin-left: 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore">1.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">依次运行</span><span lang="EN-US">qmake &#8211;pro, qmake</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">。</span></p>
<p style="line-height: 150%; text-indent: -18pt; margin-left: 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore">2.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">在</span><span lang="EN-US">Project &gt; Properties &gt; Project settings</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">中选中</span><span lang="EN-US">&#8221;This is a custom Makefile&#8221;</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">。<img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/wuxu/k.jpg" width="693" height="109" /></span></p>
<p style="line-height: 150%; text-indent: 0cm; margin-left: 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span style="mso-no-proof: yes" lang="EN-US"></span></p>
<p style="line-height: 150%; text-indent: -18pt; margin-left: 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore">3.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">如果编译的文件是</span><span lang="EN-US">GUI</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">类型，在</span><span lang="EN-US">Project &gt; Properties &gt; Build targets</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">中将</span><span lang="EN-US">Type</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">设置为</span><span lang="EN-US">&#8221;GUI application&#8221;</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">。</span></p>
<p style="line-height: 150%; text-indent: -18pt; margin-left: 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><strong style="mso-bidi-font-weight: normal"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore">4.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></strong><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">在</span><span lang="EN-US">Project &gt; Properties &gt; Build targets</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">中将</span><span lang="EN-US">Output filename</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">由原本的</span> <span lang="EN-US">&#8221;bin\debug\projectname.exe&#8221; </span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">改成</span> <span lang="EN-US">&#8221;debug\projectname.exe&#8221;</span><span>。<strong>（如果在创建工程时执行了带[&#9733;</strong></span><strong><span>]的那步，则该步不需要执行，否则必须执行。）<br /><img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/wuxu/a.jpg" width="727" height="509" /></span><span lang="EN-US"><o:p></o:p></span></strong></p>
<p style="line-height: 150%; text-indent: 0cm; margin-left: 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><strong style="mso-bidi-font-weight: normal"><span style="mso-no-proof: yes" lang="EN-US"></span><span lang="EN-US"><o:p></o:p></span></strong></p>
<p style="line-height: 150%; text-indent: -18pt; margin-left: 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore">5.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">在</span><span lang="EN-US">Project &gt; Build Options</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">中，分别选择</span><span lang="EN-US">Debug - &#8221;Make&#8221; commands</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">和</span><span lang="EN-US">Release - &#8221;Make&#8221; commands</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">，做如下修改：</span></p>
<p style="line-height: 150%; text-indent: 36.45pt; mso-char-indent-count: 3.46" class="MsoNormal"><strong style="mso-bidi-font-weight: normal"><span lang="EN-US">Clean project/target: $make -f $makefile $target-clean<br /></span></strong><strong style="mso-bidi-font-weight: normal"><span lang="EN-US"><br />&nbsp;&nbsp;&nbsp; <img border="0" alt="" src="http://www.cppblog.com/images/cppblog_com/wuxu/c.jpg" width="600" height="202" /><o:p></o:p></span></strong></p>
<p style="line-height: 150%; text-indent: 0cm; margin-left: 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span style="mso-no-proof: yes" lang="EN-US"></span></p>
<p style="line-height: 150%; text-indent: -18pt; margin-left: 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore">6.<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">运行</span><span lang="EN-US">Build</span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-hansi-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-theme-font: minor-latin">，即可生成可执行文件。<br /></span></p>
<p style="line-height: 150%" class="MsoNormal"><span lang="EN-US"><o:p><font face="宋体">注意：在Code::Blocks中调试Qt程序时，最好使用Qt官网提供的那个mingw，否则可能由于版本的原因出现不能调试的情况。</font>&nbsp;</o:p></span></p><img src ="http://www.cppblog.com/wuxu/aggbug/162596.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wuxu/" target="_blank">wuxu</a> 2011-12-22 14:54 <a href="http://www.cppblog.com/wuxu/archive/2011/12/22/162596.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>滑动窗口可视化代码</title><link>http://www.cppblog.com/wuxu/archive/2010/08/10/122875.html</link><dc:creator>wuxu</dc:creator><author>wuxu</author><pubDate>Mon, 09 Aug 2010 16:20:00 GMT</pubDate><guid>http://www.cppblog.com/wuxu/archive/2010/08/10/122875.html</guid><wfw:comment>http://www.cppblog.com/wuxu/comments/122875.html</wfw:comment><comments>http://www.cppblog.com/wuxu/archive/2010/08/10/122875.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wuxu/comments/commentRss/122875.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wuxu/services/trackbacks/122875.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 刚学编程的时候写的，留下来做个纪念。一、初步设计1、新建工程slidwindow，在MFC的向导第一步选择Single Document，按Finish结束。2、选择ResourceView窗口，打开菜单编辑器，在顶层菜单上添加&#8220;开始&#8221;和&#8220;单步&#8221;菜单，其ID分别为ID_START_SLIDWIND和ID_TRACE_SLIDWIND，在&nbsp;&...&nbsp;&nbsp;<a href='http://www.cppblog.com/wuxu/archive/2010/08/10/122875.html'>阅读全文</a><img src ="http://www.cppblog.com/wuxu/aggbug/122875.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wuxu/" target="_blank">wuxu</a> 2010-08-10 00:20 <a href="http://www.cppblog.com/wuxu/archive/2010/08/10/122875.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>