﻿<?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++博客-pzz-文章分类-c/c++</title><link>http://www.cppblog.com/panzhizhou/category/20579.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 24 Oct 2013 15:46:44 GMT</lastBuildDate><pubDate>Thu, 24 Oct 2013 15:46:44 GMT</pubDate><ttl>60</ttl><item><title>24rgb颜色转为16rgb颜色公式</title><link>http://www.cppblog.com/panzhizhou/articles/203867.html</link><dc:creator>pzz</dc:creator><author>pzz</author><pubDate>Tue, 22 Oct 2013 07:15:00 GMT</pubDate><guid>http://www.cppblog.com/panzhizhou/articles/203867.html</guid><wfw:comment>http://www.cppblog.com/panzhizhou/comments/203867.html</wfw:comment><comments>http://www.cppblog.com/panzhizhou/articles/203867.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/panzhizhou/comments/commentRss/203867.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/panzhizhou/services/trackbacks/203867.html</trackback:ping><description><![CDATA[<div style="font-size: 13px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; border-bottom: #cccccc 1px solid; word-break: break-all; padding-bottom: 4px; padding-top: 4px; padding-left: 4px; border-left: #cccccc 1px solid; padding-right: 5px; width: 98%; background-color: #eeeeee"><!--<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: #000000">#include</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;3</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;4</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />unsigned&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;make16color(unsigned&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;r,&nbsp;unsigned&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;g,&nbsp;unsigned&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;b)<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img onclick="this.style.display='none'; Codehighlighter1_114_231_Open_Text.style.display='none'; Codehighlighter1_114_231_Closed_Image.style.display='inline'; Codehighlighter1_114_231_Closed_Text.style.display='inline';" id="Codehighlighter1_114_231_Open_Image" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img onclick="this.style.display='none'; Codehighlighter1_114_231_Closed_Text.style.display='none'; Codehighlighter1_114_231_Open_Image.style.display='inline'; Codehighlighter1_114_231_Open_Text.style.display='inline';" id="Codehighlighter1_114_231_Closed_Image" style="display: none" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span id="Codehighlighter1_114_231_Closed_Text" style="border-top: #808080 1px solid; border-right: #808080 1px solid; border-bottom: #808080 1px solid; border-left: #808080 1px solid; display: none; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_114_231_Open_Text"><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/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;((((r&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0x1f</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">11</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">|</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/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;(((g&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">2</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0x3f</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">5</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">|</span><span style="color: #000000">&nbsp;((b&nbsp;</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">3</span><span style="color: #000000">)&nbsp;</span><span style="color: #000000">&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0x1f</span><span style="color: #000000">));<br /></span><span style="color: #008080">&nbsp;8</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">&nbsp;9</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><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="" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img onclick="this.style.display='none'; Codehighlighter1_245_378_Open_Text.style.display='none'; Codehighlighter1_245_378_Closed_Image.style.display='inline'; Codehighlighter1_245_378_Closed_Text.style.display='inline';" id="Codehighlighter1_245_378_Open_Image" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img onclick="this.style.display='none'; Codehighlighter1_245_378_Closed_Text.style.display='none'; Codehighlighter1_245_378_Open_Image.style.display='inline'; Codehighlighter1_245_378_Open_Text.style.display='inline';" id="Codehighlighter1_245_378_Closed_Image" style="display: none" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span id="Codehighlighter1_245_378_Closed_Text" style="border-top: #808080 1px solid; border-right: #808080 1px solid; border-bottom: #808080 1px solid; border-left: #808080 1px solid; display: none; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_245_378_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;r,g,b;<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(cin</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">r</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">g</span><span style="color: #000000">&gt;&gt;</span><span style="color: #000000">b)<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img onclick="this.style.display='none'; Codehighlighter1_293_339_Open_Text.style.display='none'; Codehighlighter1_293_339_Closed_Image.style.display='inline'; Codehighlighter1_293_339_Closed_Text.style.display='inline';" id="Codehighlighter1_293_339_Open_Image" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img onclick="this.style.display='none'; Codehighlighter1_293_339_Closed_Text.style.display='none'; Codehighlighter1_293_339_Open_Image.style.display='inline'; Codehighlighter1_293_339_Open_Text.style.display='inline';" id="Codehighlighter1_293_339_Closed_Image" style="display: none" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_293_339_Closed_Text" style="border-top: #808080 1px solid; border-right: #808080 1px solid; border-bottom: #808080 1px solid; border-left: #808080 1px solid; display: none; background-color: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"  alt="" /></span><span id="Codehighlighter1_293_339_Open_Text"><span style="color: #000000">{<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;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">make16color(r,g,b)</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">16</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">17</span><span style="color: #000000"><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif"  alt="" />&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">);<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;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">19</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">20</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/panzhizhou/aggbug/203867.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/panzhizhou/" target="_blank">pzz</a> 2013-10-22 15:15 <a href="http://www.cppblog.com/panzhizhou/articles/203867.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c++中capacity()函数用法</title><link>http://www.cppblog.com/panzhizhou/articles/203772.html</link><dc:creator>pzz</dc:creator><author>pzz</author><pubDate>Wed, 16 Oct 2013 11:06:00 GMT</pubDate><guid>http://www.cppblog.com/panzhizhou/articles/203772.html</guid><wfw:comment>http://www.cppblog.com/panzhizhou/comments/203772.html</wfw:comment><comments>http://www.cppblog.com/panzhizhou/articles/203772.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/panzhizhou/comments/commentRss/203772.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/panzhizhou/services/trackbacks/203772.html</trackback:ping><description><![CDATA[<div style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(54,46,43); text-align: left; font: 14px/26px Arial; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-stroke-width: 0px">size()指 目前存在的元素数。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 元素个数</div>
<div style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(54,46,43); text-align: left; font: 14px/26px Arial; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-stroke-width: 0px">capacity()指 容器能存储 数据的个数&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 容器 容量</div>
<div style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(54,46,43); text-align: left; font: 14px/26px Arial; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-stroke-width: 0px">reserve()指定 容器 能存储数据的个数</div>
<div style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(54,46,43); text-align: left; font: 14px/26px Arial; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-stroke-width: 0px">resize() &nbsp;重新 指定 有效元素的个数 ，区别与reserve()指定 容量的大小</div>
<div style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(54,46,43); text-align: left; font: 14px/26px Arial; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-stroke-width: 0px">当创建空容器时， 容量(capacity)为 0;当用完时，增加原容量的 1/2 （各编译器 可能存在差异 &nbsp;vs2010是这样的，mingw则 增加原容量 ）--<span style="color: rgb(255,0,0)"><strong>适用如 vector这种 元素连续存储的容器， 如为list则不同。</strong></span></div>
<div style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(54,46,43); text-align: left; font: 14px/26px Arial; letter-spacing: normal; background-color: rgb(255,255,255); text-indent: 0px; -webkit-text-stroke-width: 0px"><span style="color: rgb(255,0,0)"><strong>capacity 一般大于size的原因是为了避免 每次增加数据时都要重新分配内存，所以一般会 生成一个较大的空间，以便随后的数据插入。 
<div style="font-size: 13px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; border-bottom: #cccccc 1px solid; word-break: break-all; padding-bottom: 4px; padding-top: 4px; padding-left: 4px; border-left: #cccccc 1px solid; padding-right: 5px; width: 98%; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">&nbsp;1</span><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">iostream</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">vector</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">namespace</span><span style="color: #000000">&nbsp;std;<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" />&nbsp;<br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img onclick="this.style.display='none'; Codehighlighter1_72_971_Open_Text.style.display='none'; Codehighlighter1_72_971_Closed_Image.style.display='inline'; Codehighlighter1_72_971_Closed_Text.style.display='inline';" id="Codehighlighter1_72_971_Open_Image" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img onclick="this.style.display='none'; Codehighlighter1_72_971_Closed_Text.style.display='none'; Codehighlighter1_72_971_Open_Image.style.display='inline'; Codehighlighter1_72_971_Open_Text.style.display='inline';" id="Codehighlighter1_72_971_Closed_Image" style="display: none" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif"></span><span id="Codehighlighter1_72_971_Closed_Text" style="border-top: #808080 1px solid; border-right: #808080 1px solid; border-bottom: #808080 1px solid; border-left: #808080 1px solid; display: none; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_72_971_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;vector</span><span style="color: #000000">&lt;</span><span style="color: #0000ff">int</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;ivec;<br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">capacity:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.capacity()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;&nbsp;size:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.size()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #008000">//</span><span style="color: #008000">添加10个元素</span><span style="color: #008000"><br /></span><span style="color: #008080">10</span><span style="color: #008000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #000000">&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&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;&nbsp;i&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">10</span><span style="color: #000000">;&nbsp;</span><span style="color: #000000">++</span><span style="color: #000000">i)<br /></span><span style="color: #008080">11</span><span style="color: #000000"><img onclick="this.style.display='none'; Codehighlighter1_212_319_Open_Text.style.display='none'; Codehighlighter1_212_319_Closed_Image.style.display='inline'; Codehighlighter1_212_319_Closed_Text.style.display='inline';" id="Codehighlighter1_212_319_Open_Image" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img onclick="this.style.display='none'; Codehighlighter1_212_319_Closed_Text.style.display='none'; Codehighlighter1_212_319_Open_Image.style.display='inline'; Codehighlighter1_212_319_Open_Text.style.display='inline';" id="Codehighlighter1_212_319_Closed_Image" style="display: none" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">&nbsp;&nbsp;&nbsp;&nbsp;</span><span id="Codehighlighter1_212_319_Closed_Text" style="border-top: #808080 1px solid; border-right: #808080 1px solid; border-bottom: #808080 1px solid; border-left: #808080 1px solid; display: none; background-color: #ffffff"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_212_319_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">12</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ivec.push_back(i);<br /></span><span style="color: #008080">13</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">capacity:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.capacity()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;&nbsp;size:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.size()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">14</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">15</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #008000">//</span><span style="color: #008000">将容量用完</span><span style="color: #008000"><br /></span><span style="color: #008080">16</span><span style="color: #008000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(ivec.size()&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;ivec.capacity())<br /></span><span style="color: #008080">17</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ivec.push_back(</span><span style="color: #000000">0</span><span style="color: #000000">);<br /></span><span style="color: #008080">18</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">添加1个元素</span><span style="color: #008000"><br /></span><span style="color: #008080">19</span><span style="color: #008000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">size&nbsp;=&nbsp;capacity.&nbsp;insert&nbsp;one&nbsp;element\n</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #008080">20</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;ivec.push_back(</span><span style="color: #000000">0</span><span style="color: #000000">);<br /></span><span style="color: #008080">21</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">capacity:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.capacity()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;&nbsp;size:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.size()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">22</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;<br /></span><span style="color: #008080">23</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;ivec.reserve(</span><span style="color: #000000">100</span><span style="color: #000000">);<br /></span><span style="color: #008080">24</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">reserve&nbsp;capacity&nbsp;100\n</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #008080">25</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">capacity:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.capacity()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;&nbsp;size:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.size()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">26</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;<br /></span><span style="color: #008080">27</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&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">28</span><span style="color: #008000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">while</span><span style="color: #000000">(ivec.size()&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;ivec.capacity())<br /></span><span style="color: #008080">29</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ivec.push_back(</span><span style="color: #000000">42</span><span style="color: #000000">);<br /></span><span style="color: #008080">30</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">添加1个元素</span><span style="color: #008000"><br /></span><span style="color: #008080">31</span><span style="color: #008000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">size&nbsp;=&nbsp;capacity.&nbsp;insert&nbsp;one&nbsp;element\n</span><span style="color: #000000">"</span><span style="color: #000000">;<br /></span><span style="color: #008080">32</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;ivec.push_back(</span><span style="color: #000000">0</span><span style="color: #000000">);<br /></span><span style="color: #008080">33</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;cout</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">capacity:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.capacity()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;&nbsp;size:</span><span style="color: #000000">"</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">ivec.size()</span><span style="color: #000000">&lt;&lt;</span><span style="color: #000000">endl;<br /></span><span style="color: #008080">34</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;<br /></span><span style="color: #008080">35</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&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">);<br /></span><span style="color: #008080">36</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">37</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span><span style="color: #000000"><br /></span><span style="color: #008080">38</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span></div><br />&nbsp;<br /><span style="color: red"></span>2. capacity - 容器的成员函数capacity()取得 
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">max_size - 容器的成员函数max_size()取得</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">STL容器的capacity属性，表示STL在发生realloc前能允许的最大元素数，也可以理解为预分配的内存空间。例如一个vector&lt;int&gt; v的capacity为5，当插入第6个元素时，vector会realloc，vector内部数据会复制到另外一个内存区域。这样之前指向vector中的元素的指针、迭代器等等均会失效。</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">max_size属性和capacity不同，表示STL容器允许的最大元素数，通常，这个数是一个很大的常整数，可以理解为无穷大。这个数目与平台和实现相关，在我的机器上vector&lt;int&gt;的max_size为1073741823，而string的max_size为4294967294。因为max_size很大~所以基本不会发生元素数超过max_size的情况，只需知道两者区别即可。</p>
<h2 style="font-size: 20px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant: normal; white-space: normal; text-transform: none; word-spacing: 0px; font-weight: bold; color: rgb(0,0,0); padding-bottom: 0px; font-style: normal; text-align: left; padding-top: 0px; padding-left: 0px; margin: 15px auto 2px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">设定capacity</h2>
<h3 style="font-size: 16px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant: normal; white-space: normal; text-transform: none; word-spacing: 0px; font-weight: bold; color: rgb(0,0,0); padding-bottom: 0px; font-style: normal; text-align: left; padding-top: 0px; padding-left: 0px; margin: 15px auto 2px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">List, Map/Multimap, Set/Multiset, Deque</h3>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">并不是所有的容器都会发生realloc，List，Map/Multimap，Set/Multiset的元素在内存中散布，不预分配内存，所以不会产生realloc的情况，对于这些容器，其capacity是无意义的，所以这些容器没有capacity()成员函数，也没有capacity属性。</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">deque双向队列情况比较特殊，deque将内存分块，每次分配固定大小的分块，一个分块填充满后开辟新的分块，也属于散布-连续混杂的情况，虽然deque会预分配内存空间，但也不会产生realloc（人家是alloc），所以也不具有capacity属性。</p>
<h3 style="font-size: 16px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant: normal; white-space: normal; text-transform: none; word-spacing: 0px; font-weight: bold; color: rgb(0,0,0); padding-bottom: 0px; font-style: normal; text-align: left; padding-top: 0px; padding-left: 0px; margin: 15px auto 2px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">Vector, String, basic_string&lt;wchar_t&gt;</h3>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">实际具有capacity属性的容器只有vector和string，在不同实现下，capacity也不尽相同。在我的机器上，情况如下：</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">vector&lt;T&gt;</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">默认构造函数 - capacity = 0</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">使用构造函数vector&lt;T&gt;(n, value=T())指定capacity - capacity = n</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">string&nbsp; （basic_string&lt;char&gt; ）</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">默认构造函数 - capacity = 15</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">没有指定capacity的构造式</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">指定了初始字符串的 - capacity = 大于字符串长度且等于n*15-1</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">&nbsp;basic_string&lt;wchar_t&gt;</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">默认构造函数 - capacity = 7</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">指定了初始字符串的 - capacity = 大于字符串长度且等于n*8-1</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">&nbsp;</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">除了通过构造式设定capacity，也可以使用reserve(n)来设定容器对象的capacity，避免之后的realloc。不过这一过程是只增不减的，如果n小于当前capacity，则reserve(n)无效。</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">&nbsp;</p>
<h2 style="font-size: 20px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant: normal; white-space: normal; text-transform: none; word-spacing: 0px; font-weight: bold; color: rgb(0,0,0); padding-bottom: 0px; font-style: normal; text-align: left; padding-top: 0px; padding-left: 0px; margin: 15px auto 2px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">收缩容器的内存占用空间</h2>
<h3 style="font-size: 16px; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-variant: normal; white-space: normal; text-transform: none; word-spacing: 0px; font-weight: bold; color: rgb(0,0,0); padding-bottom: 0px; font-style: normal; text-align: left; padding-top: 0px; padding-left: 0px; margin: 15px auto 2px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">Vector, String, basic_string&lt;wchar_t&gt;</h3>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">对于vector和string，因为reserve()的效果是只增不减，所以无法通过reserve()来收缩空间。如需收缩内存空间，思路如下：</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">新建一个vector/string</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">为新建的vector/string填充原容器的内容</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto 10px 30px; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">将原容器的变量名指向新的容器</p>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">实际使用中只需要一条语句即可。</p>
<div class="cnblogs_code" style="overflow: auto; font-size: 12px !important; border-top: rgb(204,204,204) 1px solid; font-family: 'Courier New' !important; border-right: rgb(204,204,204) 1px solid; font-variant: normal; white-space: normal; border-bottom: rgb(204,204,204) 1px solid; text-transform: none; word-spacing: 0px; font-weight: normal; color: rgb(0,0,0); padding-bottom: 5px; font-style: normal; text-align: left; padding-top: 5px; padding-left: 5px; margin: 5px 0px; border-left: rgb(204,204,204) 1px solid; letter-spacing: normal; padding-right: 5px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px"><pre style="word-wrap: break-word; font-size: 12px !important; font-family: 'Courier New' !important; white-space: pre-wrap; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px">    vector&lt;<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">int</span>&gt; v(<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(128,0,128); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">10</span>, <span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(128,0,128); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">5</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">);
    v.reserve(</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(128,0,128); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">20</span><span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,0); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">);
    <strong style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px">vector</strong></span><strong style="padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px">&lt;<span style="font-size: 12px !important; font-family: 'Courier New' !important; color: rgb(0,0,255); padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; line-height: 1.5 !important; padding-right: 0px">int</span>&gt;(v).swap(v);</strong></pre></div>
<p style="white-space: normal; text-transform: none; word-spacing: 0px; color: rgb(0,0,0); padding-bottom: 0px; text-align: left; padding-top: 0px; font: 13px/19px 'Helvetica Neue', Helvetica, Arial, sans-serif; padding-left: 0px; margin: 10px auto; letter-spacing: normal; padding-right: 0px; background-color: rgb(245,245,245); text-indent: 0px; -webkit-text-stroke-width: 0px">&nbsp;<br />3.参考:<a href="http://www.cnblogs.com/SelaSelah/archive/2012/05/30/2526736.html">http://www.cnblogs.com/SelaSelah/archive/2012/05/30/2526736.html</a><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="http://blog.csdn.net/youxin2012/article/details/9213539">http://blog.csdn.net/youxin2012/article/details/9213539</a><br /></strong></span></p></div><img src ="http://www.cppblog.com/panzhizhou/aggbug/203772.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/panzhizhou/" target="_blank">pzz</a> 2013-10-16 19:06 <a href="http://www.cppblog.com/panzhizhou/articles/203772.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c++中set放结构体，默认插入排好序</title><link>http://www.cppblog.com/panzhizhou/articles/202318.html</link><dc:creator>pzz</dc:creator><author>pzz</author><pubDate>Sat, 03 Aug 2013 02:07:00 GMT</pubDate><guid>http://www.cppblog.com/panzhizhou/articles/202318.html</guid><wfw:comment>http://www.cppblog.com/panzhizhou/comments/202318.html</wfw:comment><comments>http://www.cppblog.com/panzhizhou/articles/202318.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/panzhizhou/comments/commentRss/202318.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/panzhizhou/services/trackbacks/202318.html</trackback:ping><description><![CDATA[c++中set放结构体，默认插入排好序<br /><div>#include&lt;iostream&gt;</div><div>#include&lt;set&gt;</div><div>#include&lt;algorithm&gt;</div><div>#include&lt;iterator&gt;</div><div>using namespace std;</div><div>typedef struct rect</div><div>{</div><div>&nbsp; &nbsp; &nbsp;int id;</div><div>&nbsp; &nbsp; &nbsp;int height;</div><div>&nbsp; &nbsp; &nbsp;int width;</div><div>&nbsp; &nbsp; &nbsp;bool operator &lt; (const rect &amp;rhs) const &nbsp; &nbsp; &nbsp; //set中放结构体必不可少&nbsp;</div><div>&nbsp; &nbsp; { &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if(rhs.id!=id) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//从小到大排序&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return rhs.id&gt;id;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(rhs.width!=width)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return rhs.width&gt;width;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return rhs.height&gt;height;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;</div><div>&nbsp; &nbsp; } &nbsp;</div><div>}RECT; &nbsp;</div><div>int iscan()</div><div>{</div><div>&nbsp; &nbsp; return 1;</div><div>} &nbsp; &nbsp;</div><div>int main()</div><div>{</div><div>&nbsp; &nbsp; int ncase;</div><div>&nbsp; &nbsp; int nlines;</div><div>&nbsp; &nbsp; set&lt;RECT&gt; result;</div><div>&nbsp; &nbsp; cin&gt;&gt;ncase;</div><div>&nbsp; &nbsp; while(ncase--)</div><div>&nbsp; &nbsp; {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; result.clear();</div><div>&nbsp; &nbsp; &nbsp; &nbsp; cin&gt;&gt;nlines;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; for(int i=0;i&lt;nlines;i++)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int id,data1,data2;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cin&gt;&gt;id&gt;&gt;data1&gt;&gt;data2;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RECT r1;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;r1.id=id;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;r1.height=min(data1,data2);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;r1.width=max(data1,data2);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result.insert(r1);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if(!iscan()) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; else{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; //sort(result.begin(),result.end(),mysort);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; set&lt;RECT&gt;::iterator it;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; for(it=result.begin();it!=result.end();it++)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cout&lt;&lt;it-&gt;id&lt;&lt;" "&lt;&lt;it-&gt;width&lt;&lt;" "&lt;&lt;it-&gt;height&lt;&lt;endl;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; } &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; } &nbsp;&nbsp;</div><div>&nbsp; // &nbsp;system("pause");</div><div>&nbsp; &nbsp; return 0;&nbsp;</div><div>} &nbsp; &nbsp;</div><div></div><br /><br /><br /><img src ="http://www.cppblog.com/panzhizhou/aggbug/202318.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/panzhizhou/" target="_blank">pzz</a> 2013-08-03 10:07 <a href="http://www.cppblog.com/panzhizhou/articles/202318.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>eclipse配置c++</title><link>http://www.cppblog.com/panzhizhou/articles/202264.html</link><dc:creator>pzz</dc:creator><author>pzz</author><pubDate>Wed, 31 Jul 2013 11:35:00 GMT</pubDate><guid>http://www.cppblog.com/panzhizhou/articles/202264.html</guid><wfw:comment>http://www.cppblog.com/panzhizhou/comments/202264.html</wfw:comment><comments>http://www.cppblog.com/panzhizhou/articles/202264.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/panzhizhou/comments/commentRss/202264.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/panzhizhou/services/trackbacks/202264.html</trackback:ping><description><![CDATA[1.一开始在eclipse的install software中安装了CDT插件，然后我装了DEV c++之后，就像用它的gcc,和g++于是在eclipse的c/c++编译环境中添加了path后，编译顺利通过，另外,我还用了MinGw，这个在系统path后面加上MinGw目录下的bin目录后，然后改动<span style="color: #454545; font-family: tahoma, helvetica, arial;">MinGW\bin\mingw32-make.exe这个文件，改名为make.exe.之后我另外创建了一个工作空间，发现自动导入了MinGw的include文件，现在问题是在这个下面，一旦运行c++程序就发生the selection cannot be launched,and there are no recent launches. 问题到底是什么情况呢。<br />&nbsp; &nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp;参考文章：</span><a href="http://hi.baidu.com/youzi0730/item/17f00059e77bd63d32e0a901">http://hi.baidu.com/youzi0730/item/17f00059e77bd63d32e0a901</a><span style="color: #454545; font-family: tahoma, helvetica, arial;"><br /><br /><br />2.啥都不收了，下载eclipse for c/c++然后配合MinGw，MinGW的改动如上，然后建立c++工程成功运行。</span>2013年8月8日<span style="color: #454545; font-family: tahoma, helvetica, arial;"><br /><br /><br /><br /><br /><br /></span><img src ="http://www.cppblog.com/panzhizhou/aggbug/202264.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/panzhizhou/" target="_blank">pzz</a> 2013-07-31 19:35 <a href="http://www.cppblog.com/panzhizhou/articles/202264.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux字符界面下显示中文，安装zhcon</title><link>http://www.cppblog.com/panzhizhou/articles/202192.html</link><dc:creator>pzz</dc:creator><author>pzz</author><pubDate>Sun, 28 Jul 2013 07:30:00 GMT</pubDate><guid>http://www.cppblog.com/panzhizhou/articles/202192.html</guid><wfw:comment>http://www.cppblog.com/panzhizhou/comments/202192.html</wfw:comment><comments>http://www.cppblog.com/panzhizhou/articles/202192.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/panzhizhou/comments/commentRss/202192.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/panzhizhou/services/trackbacks/202192.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;">1.下载zhcon-0.2.5-to-0.2.6.diff.gz和zhcon-0.2.5.tar.gz两个包</span></div><div><span style="font-size: 12px;">&nbsp; wget http://sourceforge.net/projects/zhcon/files/zhcon/0.2.6/zhcon-0.2.5.tar.gz</span></div><div><span style="font-size: 12px;">&nbsp; wget http://sourceforge.net/projects/zhcon/files/zhcon/0.2.6/zhcon-0.2.5-to-0.2.6.diff.gz</span></div><div><span style="font-size: 12px;">2.tar zxvf zhcon-0.2.5.tar.gz</span></div><div><span style="font-size: 12px;">&nbsp; gunzip zhcon-0.2.5-to-0.2.6.diff.gz</span></div><div><span style="font-size: 12px;">&nbsp; cd zhcon-0.2.5/</span></div><div><span style="font-size: 12px;">&nbsp; patch -p1 &lt; ../zhcon-0.2.5-to-0.2.6.diff&nbsp;</span></div><div><span style="font-size: 12px;">3 ./configure 加入编译到指定的目录 则命令为：./configure --prefix=opt/EmbedSky/4.3.3 (最后不用加/）</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;make</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;此处可能会出现错误，是因为缺少有些头文件，根据错误，一般memset等没定义，在相应的源文件或者头文件加入string.h</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;还有可能有些变量未定义：</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;在zhcon的make过程中，有很多次报错，说缺少memset，memcpy等函数的定义，是缺少#include &lt;string.h&gt;；有几次缺少abs，atoi，free等的定义，</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;是缺少#include &lt;stdlib.h&gt;；还有报fd_set结构的定义，是缺少#include &lt;sys/select.h&gt;；</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;另外，缺少几个常量定义，我从以前版本的内核头文件中找到，然后写入了src/lrmi.c中（好像就是这个 文件缺），共用到如下几个量：</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;#define VIF_MASK &nbsp; &nbsp; &nbsp; &nbsp;0x00080000 &nbsp; &nbsp; &nbsp;/* virtual interrupt flag */</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;#define IF_MASK &nbsp; &nbsp; &nbsp; &nbsp; 0x00000200</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;#define IOPL_MASK &nbsp; &nbsp; &nbsp; 0x00003000</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;#define TF_MASK &nbsp; &nbsp; &nbsp; &nbsp; 0x00000100&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;这样过后make可以成功</span><span style="font-size: 12px;">&nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;然后make install</span></div><div><span style="font-size: 12px;">4. 启动字符界面，这是输入zhcon --utf8 可能还会出现问题，这时一个是修改zhcon.conf 文件，还有一个非常重要的是修改，把</span></div><div><span style="font-size: 12px;">#x_resolution = 640</span></div><div><span style="font-size: 12px;">#y_resolution = 480</span></div><div><span style="font-size: 12px;">x_resolution = 800 &nbsp; //修改分辨率</span></div><div><span style="font-size: 12px;">y_resolution = 600</span></div><div></div><div><span style="font-size: 12px;">#color_depth = 4</span></div><div><span style="font-size: 12px;">color_depth = 8</span></div><div><span style="font-size: 12px;">&nbsp;还有一个非常重要的修改是：修改grub启动文件,改分辨率，在/boot/grub/grub.conf里的kernel项追加&#8220;vga=0x307&#8221;后为</span></div><div><span style="font-size: 12px;">&nbsp;这个在你输入zhcon --utf8时可能会告诉你说没法启动fremebuffer等东东，这时你在这里kernel后面加入即可</span></div><div><span style="font-size: 12px;">&nbsp;kernel /boot/vmlinuz-2.6.25-14.fc9.i686 ro root=UUID=4f04913b-3dd1-4aea-945a-2e64c44665e5 rhgb quiet vga=0x307</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;initrd /boot/initrd-2.6.25-14.fc9.i686.img</span></div><div><span style="font-size: 12px;">5.现在输入命令就会出现界面了，成功&nbsp;</span></div><div><span style="font-size: 12px;">6.移植问题，这里重要的是把编译好的可执行文件，配置文件还有包含的一些文件拷打linux系统下面就可以了，如：</span></div><div><span style="font-size: 12px;">&nbsp; 我是在 opt/EmbedSky/4.3.3/ &nbsp;下的，所以在该目录的bin目录下会有一个zhcon可执行文件，还有在该目录下的lib目录下会有一个</span></div><div><span style="font-size: 12px;">&nbsp; zhcon的目录，里面有font和input文件 ，还有一个就是该目录下的etc的目录会有一个zhcon.conf当移植到其他开发板上时可能其他地方没有这个目录</span></div><div><span style="font-size: 12px;">这个你自己在创建下即可，把这三个文件相应的拷贝到开发板上的相应目录，如在我的目标移植系统上有/opt/EmbedSky/4.3.3/ 目录，所以你就拷贝到相应的lib和bin目录下</span></div><div><span style="font-size: 12px;">以及etc等目录下的zonch.conf (这里拷贝到/usr/bin 和/usr/lib ，/usr/etc 应该也性，没试）</span></div><div><span style="font-size: 12px;">7.这样在目标系统下的字符界面下可以显示中文了</span></div><div><span style="font-size: 12px;">8.参考文章:</span></div><div><span style="font-size: 12px;">1.http://blog.163.com/jw_chen_cs/blog/static/20221214820126185371482/</span></div><div><span style="font-size: 12px;">2.http://www.linuxidc.com/Linux/2010-05/26183.htm</span></div><div><span style="font-size: 12px;">3.http://hi.baidu.com/liang_zuokui/item/8822d3c4637b5c6588ad9eca</span></div><div style="font-family: Tahoma; font-size: 11px;"></div><img src ="http://www.cppblog.com/panzhizhou/aggbug/202192.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/panzhizhou/" target="_blank">pzz</a> 2013-07-28 15:30 <a href="http://www.cppblog.com/panzhizhou/articles/202192.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ubuntu13.04和window下的文件共享，用smb服务来做</title><link>http://www.cppblog.com/panzhizhou/articles/201499.html</link><dc:creator>pzz</dc:creator><author>pzz</author><pubDate>Wed, 03 Jul 2013 12:46:00 GMT</pubDate><guid>http://www.cppblog.com/panzhizhou/articles/201499.html</guid><wfw:comment>http://www.cppblog.com/panzhizhou/comments/201499.html</wfw:comment><comments>http://www.cppblog.com/panzhizhou/articles/201499.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/panzhizhou/comments/commentRss/201499.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/panzhizhou/services/trackbacks/201499.html</trackback:ping><description><![CDATA[<p><font color="#000000" face="Verdana">1.安装smb服务。<br />&nbsp; sudo apt-get install samba<br />&nbsp; sudo apt-get install smbfs<br />&nbsp; sudo apt-get install system-config-samba<br />&nbsp; <br />2.启动samba图形管理界面<br />&nbsp; #sudo system-config-samba</font></p>
<p><font color="#000000" face="Verdana">3.选择共享的目录<br />4.重启smb服务:/etc/init.d/smbd restart （注意这里用smbd而不是samba,我用samba说找不到不知道怎么回事，可能版本问题）<br />5.windows下在cmd输入linux下的ip地址（在ubuntu下输入ipconfig可以查看ip地址）</font></p>
<p><font color="#000000" face="Verdana">6.参考文章:<br />http://www.cnblogs.com/amishe/p/3162236.html<br />http://blog.csdn.net/xt_xiaotian/article/details/4216408<br />http://blog.163.com/liwenhoho@126/blog/static/171042060201182125633236/</font></p><img src ="http://www.cppblog.com/panzhizhou/aggbug/201499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/panzhizhou/" target="_blank">pzz</a> 2013-07-03 20:46 <a href="http://www.cppblog.com/panzhizhou/articles/201499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>安装ncurses</title><link>http://www.cppblog.com/panzhizhou/articles/201401.html</link><dc:creator>pzz</dc:creator><author>pzz</author><pubDate>Sun, 30 Jun 2013 02:57:00 GMT</pubDate><guid>http://www.cppblog.com/panzhizhou/articles/201401.html</guid><wfw:comment>http://www.cppblog.com/panzhizhou/comments/201401.html</wfw:comment><comments>http://www.cppblog.com/panzhizhou/articles/201401.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/panzhizhou/comments/commentRss/201401.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/panzhizhou/services/trackbacks/201401.html</trackback:ping><description><![CDATA[<p><font color="#000000" face="Verdana"><font color="#000000" face="Verdana">1.下载这个包<a href="ftp://ftp.gnu.org/pub/gnu/ncurses/ncurses.tar.gz">ftp://ftp.gnu.org/pub/gnu/ncurses/ncurses.tar.gz</a>，然后解压，进入目录<br />&nbsp; tar zxvf ncurses&lt;version&gt;.tar.gz&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 解压缩并且释放文件包<br />&nbsp; cd ncurses&lt;version&gt;&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; # 进入解压缩的目录（注意版本）<br />&nbsp; ./configure&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; # 按照你的系统环境制作安装配置文件<br />&nbsp; make&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # 编译源代码并且编译ncurses 库<br />&nbsp; sudo make install&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; # 安装编译好的NCURSES 库</font></p>
<p><font color="#000000" face="Verdana">然后用编译器写一个程序测试是否安装成功,编写hello.c如下：</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 alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /><span style="color: #000000">#include&nbsp;</span><span style="color: #000000">&lt;</span><span style="color: #000000">ncurses.h</span><span style="color: #000000">&gt;</span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;2</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif" /></span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;main()<br /></span><span style="color: #008080">&nbsp;3</span><span style="color: #000000"><img id="Codehighlighter1_32_221_Open_Image" onclick="this.style.display='none'; Codehighlighter1_32_221_Open_Text.style.display='none'; Codehighlighter1_32_221_Closed_Image.style.display='inline'; Codehighlighter1_32_221_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif"><img style="display: none" id="Codehighlighter1_32_221_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_32_221_Closed_Text.style.display='none'; Codehighlighter1_32_221_Open_Image.style.display='inline'; Codehighlighter1_32_221_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_32_221_Closed_Text"><img alt="" src="http://www.cppblog.com/Images/dot.gif" /></span><span id="Codehighlighter1_32_221_Open_Text"><span style="color: #000000">{<br /></span><span style="color: #008080">&nbsp;4</span><span style="color: #000000"><img id="Codehighlighter1_45_65_Open_Image" onclick="this.style.display='none'; Codehighlighter1_45_65_Open_Text.style.display='none'; Codehighlighter1_45_65_Closed_Image.style.display='inline'; Codehighlighter1_45_65_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_45_65_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_45_65_Closed_Text.style.display='none'; Codehighlighter1_45_65_Open_Image.style.display='inline'; Codehighlighter1_45_65_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">initscr();&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_45_65_Closed_Text">/**/</span><span id="Codehighlighter1_45_65_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;初始化，进入NCURSES&nbsp;模式</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;5</span><span style="color: #000000"><img id="Codehighlighter1_94_122_Open_Image" onclick="this.style.display='none'; Codehighlighter1_94_122_Open_Text.style.display='none'; Codehighlighter1_94_122_Closed_Image.style.display='inline'; Codehighlighter1_94_122_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_94_122_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_94_122_Closed_Text.style.display='none'; Codehighlighter1_94_122_Open_Image.style.display='inline'; Codehighlighter1_94_122_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">printw(</span><span style="color: #000000">"</span><span style="color: #000000">Hello&nbsp;World&nbsp;!!!</span><span style="color: #000000">"</span><span style="color: #000000">);&nbsp;</span><span style="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_94_122_Closed_Text">/**/</span><span id="Codehighlighter1_94_122_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;在虚拟屏幕上打印Hello,&nbsp;World!!!&nbsp;</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;6</span><span style="color: #000000"><img id="Codehighlighter1_135_158_Open_Image" onclick="this.style.display='none'; Codehighlighter1_135_158_Open_Text.style.display='none'; Codehighlighter1_135_158_Closed_Image.style.display='inline'; Codehighlighter1_135_158_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_135_158_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_135_158_Closed_Text.style.display='none'; Codehighlighter1_135_158_Open_Image.style.display='inline'; Codehighlighter1_135_158_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">refresh();&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_135_158_Closed_Text">/**/</span><span id="Codehighlighter1_135_158_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;将虚拟屏幕上的内容写到显示器上，并刷新</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;7</span><span style="color: #000000"><img id="Codehighlighter1_171_181_Open_Image" onclick="this.style.display='none'; Codehighlighter1_171_181_Open_Text.style.display='none'; Codehighlighter1_171_181_Closed_Image.style.display='inline'; Codehighlighter1_171_181_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_171_181_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_171_181_Closed_Text.style.display='none'; Codehighlighter1_171_181_Open_Image.style.display='inline'; Codehighlighter1_171_181_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">getchar();&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_171_181_Closed_Text">/**/</span><span id="Codehighlighter1_171_181_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;等待用户输入</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;8</span><span style="color: #000000"><img id="Codehighlighter1_193_209_Open_Image" onclick="this.style.display='none'; Codehighlighter1_193_209_Open_Text.style.display='none'; Codehighlighter1_193_209_Closed_Image.style.display='inline'; Codehighlighter1_193_209_Closed_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif"><img style="display: none" id="Codehighlighter1_193_209_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_193_209_Closed_Text.style.display='none'; Codehighlighter1_193_209_Open_Image.style.display='inline'; Codehighlighter1_193_209_Open_Text.style.display='inline';" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif">endwin();&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_193_209_Closed_Text">/**/</span><span id="Codehighlighter1_193_209_Open_Text"><span style="color: #008000">/*</span><span style="color: #008000">&nbsp;退出NCURSES&nbsp;模式</span><span style="color: #008000">*/</span></span><span style="color: #000000"><br /></span><span style="color: #008080">&nbsp;9</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" /></span><span style="color: #0000ff">return</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span><span style="color: #000000">;<br /></span><span style="color: #008080">10</span><span style="color: #000000"><img alt="" align="top" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" />}</span></span></div>
<p></font><font color="#000000" face="Verdana">然后编译 gcc hello.c -lncurses<br />最后运行改程序即可，屏幕输出Hello world，成功装成。<br /></font></p>
<p><font color="#000000" face="Verdana">下面是在这个过程中遇到的错误：<br />1.通过终端安装程序sudo apt-get install xxx时出错：<br />&nbsp;E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)<br />&nbsp;E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?</font></p>
<p><font color="#000000" face="Verdana">解决办法:<br />&nbsp;在终端中敲入以下两句<br />&nbsp;sudo rm /var/cache/apt/archives/lock<br />&nbsp;sudo rm /var/lib/dpkg/lock<br />上面两个命令中有的目录可能不存在，可以到目录当中去看，然后手动删除之即可。</font></p>
<p><font color="#000000" face="Verdana"><br /></font>&nbsp;</p>
<p></font>&nbsp;</p><img src ="http://www.cppblog.com/panzhizhou/aggbug/201401.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/panzhizhou/" target="_blank">pzz</a> 2013-06-30 10:57 <a href="http://www.cppblog.com/panzhizhou/articles/201401.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>windows下配置c/c++的emacs编程环境</title><link>http://www.cppblog.com/panzhizhou/articles/201392.html</link><dc:creator>pzz</dc:creator><author>pzz</author><pubDate>Sat, 29 Jun 2013 09:37:00 GMT</pubDate><guid>http://www.cppblog.com/panzhizhou/articles/201392.html</guid><wfw:comment>http://www.cppblog.com/panzhizhou/comments/201392.html</wfw:comment><comments>http://www.cppblog.com/panzhizhou/articles/201392.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/panzhizhou/comments/commentRss/201392.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/panzhizhou/services/trackbacks/201392.html</trackback:ping><description><![CDATA[<div>1.首先到网站下载emacs,我用的是emacs23.1版本,下载后解压放在D盘下,目录是D:/emacs_23.1 打开后在其中bin目录下运行addpm.exe，然后就会装上emacs<br />2.HOME目录的设置问题，这里有好多方法，认为最简单的一个方法就是在注册表下，修改HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs\HOME的值，改为D:/emacs_23.1，如果没有这些文件夹就新建。这个HOME目录还是比较重要的，因为我们从别人拷来的插件，对这些插件做配置时可能会涉及到HOME目录。<br />3.接下来在D:/emacs_23.1/目录下新建.emacs.d文件夹和.emacs文件.<br />4.接下来就是从别人那里下插件，改配置了。插件一般放在site-lisp下，然后在.emacs配置文件中加入（require &#8217; 插件名称），这样重新启动emacs即可生效！！！<br /><br />参考文章:<a href="http://wenku.baidu.com/view/d799dd070740be1e650e9a9b.html">http://wenku.baidu.com/view/d799dd070740be1e650e9a9b.html</a></div><img src ="http://www.cppblog.com/panzhizhou/aggbug/201392.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/panzhizhou/" target="_blank">pzz</a> 2013-06-29 17:37 <a href="http://www.cppblog.com/panzhizhou/articles/201392.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>