锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久综合九色综合97_久久久,久久影视国产亚洲,性欧美大战久久久久久久http://www.shnenglu.com/keyws/C++ && keyWordSpottingzh-cnMon, 30 Jun 2025 18:03:59 GMTMon, 30 Jun 2025 18:03:59 GMT60銆恈ode銆戜竴涓彲浠ョ簿紜埌姣鐨勮鏃剁▼搴忎唬鐮?/title><link>http://www.shnenglu.com/keyws/archive/2006/08/29/11810.html</link><dc:creator>keyws</dc:creator><author>keyws</author><pubDate>Tue, 29 Aug 2006 01:51:00 GMT</pubDate><guid>http://www.shnenglu.com/keyws/archive/2006/08/29/11810.html</guid><wfw:comment>http://www.shnenglu.com/keyws/comments/11810.html</wfw:comment><comments>http://www.shnenglu.com/keyws/archive/2006/08/29/11810.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/keyws/comments/commentRss/11810.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/keyws/services/trackbacks/11810.html</trackback:ping><description><![CDATA[ <p>聽</p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">聽1</span>聽<span style="COLOR: #000000">#ifndef聽_GHH_TIMER_GHH_<br /></span><span style="COLOR: #008080">聽2</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">聽_GHH_TIMER_GHH_聽聽聽聽1</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽3</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽4</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽File:聽ghhTimer.h<br /></span><span style="COLOR: #008080">聽5</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Date:聽2006.08.14<br /></span><span style="COLOR: #008080">聽</span><span style="COLOR: #008080">7</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽8</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">ctime</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽9</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">10</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽綾誨鍑哄鍏ョ被鍒殑絎﹀彿瀹氫箟</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">11</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">#ifdef聽_DLL_FILE_<br /></span><span style="COLOR: #008080">12</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">聽PORTTYE聽__declspec(dllexport)聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽瀵煎嚭</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">13</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#else</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">14</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">聽PORTTYE聽__declspec(dllimport)聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽瀵煎叆</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">15</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#endif</span><span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽end聽of聽_DLL_FILE_</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">16</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">17</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">***************************************************************************<br /></span><span style="COLOR: #008080">18</span>聽<span style="COLOR: #008000">聽*聽綾誨悕縐奧犅犅犅爂hhTimer<br /></span><span style="COLOR: #008080">19</span>聽<span style="COLOR: #008000">聽*聽<br /></span><span style="COLOR: #008080">20</span>聽<span style="COLOR: #008000">聽*聽鎻忚堪<br /></span><span style="COLOR: #008080">21</span>聽<span style="COLOR: #008000">聽*聽聽聽聽鏈被瀵規爣鍑嗗簱璁℃椂鍑芥暟榪涜浜嗗皝瑁咃紝鍙互瀹炵幇闈炲父綺劇‘鐨勮鏃訛紝姣綰у埆<br /></span><span style="COLOR: #008080">22</span>聽<span style="COLOR: #008000">聽*<br /></span><span style="COLOR: #008080">23</span>聽<span style="COLOR: #008000">聽*聽浣跨敤璇存槑<br /></span><span style="COLOR: #008080">24</span>聽<span style="COLOR: #008000">聽*聽聽聽聽鍦ㄦ墍瑕佽鏃剁▼搴忔涔嬪墠錛岃皟鐢⊿tart鍑芥暟錛岀▼搴忔緇撴潫鏃訛紝璋冪敤Pause鍑芥暟錛?br /></span><span style="COLOR: #008080">25</span>聽<span style="COLOR: #008000">聽*聽聽聽聽澶氭璋冪敤紼嬪簭孌碉紝鍗沖彲浠ユ瘮杈冪簿紜殑浼拌紼嬪簭孌電殑榪愯鏃墮棿<br /></span><span style="COLOR: #008080">26</span>聽<span style="COLOR: #008000">***************************************************************************</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">27</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">聽聽PORTTYE聽ghhTimer<br /></span><span style="COLOR: #008080">28</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">29</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">30</span>聽<span style="COLOR: #000000">聽聽聽聽ghhTimer();<br /></span><span style="COLOR: #008080">31</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">32</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">33</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">聽Start(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">);聽<br /></span><span style="COLOR: #008080">34</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">聽Stop(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">);聽聽聽聽<br /></span><span style="COLOR: #008080">35</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">聽Pause(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">);<br /></span><span style="COLOR: #008080">36</span>聽<span style="COLOR: #000000">聽聽聽聽size_t聽GetSeconds(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)聽</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">37</span>聽<span style="COLOR: #000000">聽聽聽聽size_t聽GetMiliSeconds(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)聽</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">38</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">39</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">40</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">enum</span><span style="COLOR: #000000">聽{run聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">,聽stop,聽pause}聽_Status;<br /></span><span style="COLOR: #008080">41</span>聽<span style="COLOR: #000000">聽聽聽聽time_t聽_Clock;<br /></span><span style="COLOR: #008080">42</span>聽<span style="COLOR: #000000">聽聽聽聽time_t聽_TotalClocks;<br /></span><span style="COLOR: #008080">43</span>聽<span style="COLOR: #000000">};<br /></span><span style="COLOR: #008080">44</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">45</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#endif</span><span style="COLOR: #000000">聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽end聽of聽_GHH_TIMER_GHH_</span></div> <br /> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">聽聽1</span>聽<span style="COLOR: #000000">#ifndef聽_DLL_FILE_<br /></span><span style="COLOR: #008080">聽聽2</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">聽_DLL_FILE_</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽聽3</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">#endif</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽聽4</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">ghhTimer.h</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽聽5</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽聽6</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">***************************************************************************<br /></span><span style="COLOR: #008080">聽聽7</span>聽<span style="COLOR: #008000">聽*聽about聽the聽important聽function聽"clock()"<br /></span><span style="COLOR: #008080">聽聽8</span>聽<span style="COLOR: #008000">聽*聽#include聽<time.h><br /></span><span style="COLOR: #008080">聽聽9</span>聽<span style="COLOR: #008000">聽*聽clock_t聽clock(聽void聽);<br /></span><span style="COLOR: #008080">聽10</span>聽<span style="COLOR: #008000">聽*聽The聽clock()聽function聽returns聽the聽processor聽time聽since聽the聽program聽started,聽<br /></span><span style="COLOR: #008080">聽11</span>聽<span style="COLOR: #008000">聽*聽or聽-1聽if聽that聽information聽is聽unavailable.聽<br /></span><span style="COLOR: #008080">聽12</span>聽<span style="COLOR: #008000">聽*聽To聽convert聽the聽return聽value聽to聽seconds,聽divide聽it聽by聽CLOCKS_PER_SEC.聽<br /></span><span style="COLOR: #008080">聽13</span>聽<span style="COLOR: #008000">聽*聽(Note:聽if聽your聽compiler聽is聽POSIX聽compliant,聽<br /></span><span style="COLOR: #008080">聽14</span>聽<span style="COLOR: #008000">聽*聽then聽CLOCKS_PER_SEC聽is聽always聽defined聽as聽1000000.)<br /></span><span style="COLOR: #008080">聽15</span>聽<span style="COLOR: #008000">聽**************************************************************************</span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽16</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽17</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽18</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽鏋勯犲嚱鏁幫紝璁劇疆鍒濆鐘舵?/span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽19</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">ghhTimer::ghhTimer()聽:聽_Status(stop),聽_Clock(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">),聽_TotalClocks(</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">聽20</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">聽21</span>聽<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">聽22</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽23</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽褰撹〃宸茬粡鍋滄鎴栬呮殏鍋滄椂鍚姩鍋滆〃錛屾垚鍔熻繑鍥瀟rue,鍚﹀垯榪斿洖false</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽24</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">聽ghhTimer::Start(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">聽25</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">聽26</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">聽(_Status)<br /></span><span style="COLOR: #008080">聽27</span>聽<span style="COLOR: #000000">聽聽聽聽{<br /></span><span style="COLOR: #008080">聽28</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽stop聽:<br /></span><span style="COLOR: #008080">聽29</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽_TotalClocks聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽30</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽_Clock聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽clock();<br /></span><span style="COLOR: #008080">聽31</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽32</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽33</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽pause聽:<br /></span><span style="COLOR: #008080">聽34</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽_Clock聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽clock();<br /></span><span style="COLOR: #008080">聽35</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽36</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽37</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽run聽:<br /></span><span style="COLOR: #008080">聽38</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽39</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽40</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">聽:<br /></span><span style="COLOR: #008080">聽41</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽42</span>聽<span style="COLOR: #000000">聽聽聽聽}<br /></span><span style="COLOR: #008080">聽43</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽44</span>聽<span style="COLOR: #000000">聽聽聽聽_Status聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽run;<br /></span><span style="COLOR: #008080">聽45</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽46</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽47</span>聽<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">聽48</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽49</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽琛ㄨ繍琛屾椂鏆傚仠璁℃椂,鎴愬姛榪斿洖true錛屽惁鍒欒繑鍥瀎alse</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽50</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">聽ghhTimer::Pause(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">聽51</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">聽52</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">聽(_Status)<br /></span><span style="COLOR: #008080">聽53</span>聽<span style="COLOR: #000000">聽聽聽聽{<br /></span><span style="COLOR: #008080">聽54</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽stop聽:<br /></span><span style="COLOR: #008080">聽55</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽pause聽:<br /></span><span style="COLOR: #008080">聽56</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽57</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽58</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽run聽:<br /></span><span style="COLOR: #008080">聽59</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽_TotalClocks聽</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">聽(clock()聽</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">聽_Clock);<br /></span><span style="COLOR: #008080">聽60</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽_Clock聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽61</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽_Status聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽pause;<br /></span><span style="COLOR: #008080">聽62</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽63</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽64</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">聽:<br /></span><span style="COLOR: #008080">聽65</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽66</span>聽<span style="COLOR: #000000">聽聽聽聽}<br /></span><span style="COLOR: #008080">聽67</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽68</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽69</span>聽<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">聽70</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽71</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽琛ㄨ繍琛屾垨鏆傚仠鏃跺仠姝㈣鏃?/span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽72</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">聽ghhTimer::Stop(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">聽73</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">聽74</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">聽(_Status)<br /></span><span style="COLOR: #008080">聽75</span>聽<span style="COLOR: #000000">聽聽聽聽{<br /></span><span style="COLOR: #008080">聽76</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽stop聽:<br /></span><span style="COLOR: #008080">聽77</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽pause聽:<br /></span><span style="COLOR: #008080">聽78</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽79</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽<br /></span><span style="COLOR: #008080">聽80</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽run聽:<br /></span><span style="COLOR: #008080">聽81</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽_TotalClocks聽</span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000">(clock()聽</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">聽_Clock);<br /></span><span style="COLOR: #008080">聽82</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽_Clock聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽83</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽84</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽85</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">聽:<br /></span><span style="COLOR: #008080">聽86</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽87</span>聽<span style="COLOR: #000000">聽聽聽聽}<br /></span><span style="COLOR: #008080">聽88</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽89</span>聽<span style="COLOR: #000000">聽聽聽聽_Status聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽stop;<br /></span><span style="COLOR: #008080">聽90</span>聽<span style="COLOR: #000000">聽聽聽聽<br /></span><span style="COLOR: #008080">聽91</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽92</span>聽<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">聽93</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽94</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽寰楀埌褰撳墠縐瘡鐨勭鏁?/span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽95</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">size_t聽ghhTimer::GetSeconds(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)聽</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽96</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">聽97</span>聽<span style="COLOR: #000000">聽聽聽聽time_t聽Clocks;<br /></span><span style="COLOR: #008080">聽98</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽99</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">聽(_Status)<br /></span><span style="COLOR: #008080">100</span>聽<span style="COLOR: #000000">聽聽聽聽{<br /></span><span style="COLOR: #008080">101</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽stop:<br /></span><span style="COLOR: #008080">102</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽pause:<br /></span><span style="COLOR: #008080">103</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽Clocks聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽_TotalClocks;<br /></span><span style="COLOR: #008080">104</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">105</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">106</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽run:<br /></span><span style="COLOR: #008080">107</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽Clocks聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽_TotalClocks聽</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">聽clock()聽</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">聽_Clock;<br /></span><span style="COLOR: #008080">108</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">109</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">110</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">111</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">112</span>聽<span style="COLOR: #000000">聽聽聽聽}<br /></span><span style="COLOR: #008080">113</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽(Clocks聽</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">聽CLOCKS_PER_SEC);<br /></span><span style="COLOR: #008080">114</span>聽<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">115</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">116</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽寰楀埌褰撳墠縐瘡鐨勬縐掓暟</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">117</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">size_t聽ghhTimer::GetMiliSeconds(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)聽</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">118</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">119</span>聽<span style="COLOR: #000000">聽聽聽聽time_t聽Clocks;<br /></span><span style="COLOR: #008080">120</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">121</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">switch</span><span style="COLOR: #000000">(_Status)<br /></span><span style="COLOR: #008080">122</span>聽<span style="COLOR: #000000">聽聽聽聽{<br /></span><span style="COLOR: #008080">123</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽stop:<br /></span><span style="COLOR: #008080">124</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽pause:<br /></span><span style="COLOR: #008080">125</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽Clocks聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽_TotalClocks;<br /></span><span style="COLOR: #008080">126</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">127</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">case</span><span style="COLOR: #000000">聽run:<br /></span><span style="COLOR: #008080">128</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽Clocks聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽_TotalClocks聽</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">聽clock()聽</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">聽_Clock;<br /></span><span style="COLOR: #008080">129</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">130</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">131</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">default</span><span style="COLOR: #000000">:<br /></span><span style="COLOR: #008080">132</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">133</span>聽<span style="COLOR: #000000">聽聽聽聽}<br /></span><span style="COLOR: #008080">134</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽(Clocks聽</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">聽CLOCKS_PER_SEC);<br /></span><span style="COLOR: #008080">135</span>聽<span style="COLOR: #000000">}<br /></span><span style="COLOR: #008080">136</span>聽<span style="COLOR: #000000"></span></div> <img src ="http://www.shnenglu.com/keyws/aggbug/11810.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/keyws/" target="_blank">keyws</a> 2006-08-29 09:51 <a href="http://www.shnenglu.com/keyws/archive/2006/08/29/11810.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>銆恘ote銆慐ffective C++ (2) - Shifting from C to C++http://www.shnenglu.com/keyws/archive/2006/08/22/11580.htmlkeywskeywsTue, 22 Aug 2006 09:24:00 GMThttp://www.shnenglu.com/keyws/archive/2006/08/22/11580.htmlhttp://www.shnenglu.com/keyws/comments/11580.htmlhttp://www.shnenglu.com/keyws/archive/2006/08/22/11580.html#Feedback0http://www.shnenglu.com/keyws/comments/commentRss/11580.htmlhttp://www.shnenglu.com/keyws/services/trackbacks/11580.html Shifting from C to C++

1. To C++ programmer, for example, a pointer to a pointer looks a little funny. Why, we wonder, wasn鈥檛 a reference to a pointer used instead?

聽聽聽聽聽聽 const char chr[] = "chenzhenshi&guohonghua";

聽聽聽聽聽聽 const char*pchr = chr;

聽聽聽聽聽聽 const char** ppchr = &pchr;

聽聽聽聽聽聽 const char*&rpchr= pchr; // a reference to a pointer

聽聽聽聽聽聽 std::cout << pchr << ' ' << *ppchr << ' ' << rpchr << std::endl;

2. C is a fairly simple language. All it really offers is macros, pointers, structs, arrays, and functions. No matter what the problem is, the solution will always boil down to macros, pointers, structs, arrays, and functions. Not so in C++. The macros, pointers, structs, arrays and functions are still there, of course, but so are private and protected members, function overloading, default parameters, constructors and destructors, user-defined operators, inline functions, references, friends, templates, exceptions, namespaces, and more. The design space is much richer in C++ than it is in C: there are just a lot more options to consider.

Item 1: Prefer const and inline to #define

3. The Item might better be called 鈥減refer the compiler to the preprocessor鈥?

4. 聽聽 const char* pc;

聽聽聽聽聽聽 pc = a1;

聽聽聽聽聽聽 std::cout << pc << std::endl;

聽聽聽聽聽聽 pc = a2;

聽聽聽聽聽聽 std::cout << pc << std::endl;

聽聽聽聽聽聽 const char* const pcc = "a const pointer to a const char array";

聽聽聽聽聽聽 std::cout << pcc << std::endl;

聽聽聽聽聽聽 // error C2166: l-value specifies const object

聽聽聽聽聽聽 // pcc = a1;// error!

聽聽聽聽聽聽 std::cout << pcc << std::endl;

5. You can define a const variable in a class, but it must be static const, and have a definition in an implementation file.

// .h file

class try_const

{

public:

聽聽聽聽聽聽 static const int num;

};

// .cxx file

const int try_const::num = 250;

6. You can get all the efficiency of a macro plus all the predictable behavior and type safety of a regular function by using an inline function.

Template <class type>

Inline const type& max (const type& a, const type& b)

{

Return a > b ? a : b ;

}

7. Given the availability of consts and inlines, your need for the preprocessor is reduced, but it's not completely eliminated. The day is far from near when you can abandon #include, and #ifdef/#ifndef continue to play important roles in controlling compilation. It's not yet time to retire the preprocessor, but you should definitely plan to start giving it longer and more frequent vacations.

Item 2: Prefer <iostream> to <stdio.h>

8. scanf and printf are not type-safe and extensible.

9.In particular, if you #include <iostream>, you get the elements of the iostream library ensconced within the namespace std (see Item 28), but if you #include <iostream.h>, you get those same elements at global scope. Getting them at global scope can lead to name conflicts, precisely the kinds of name conflicts the use of namespaces is designed to prevent.

Item 3: Prefer new and delete to malloc and free

10. The problem with malloc and free(and their variants) is simple : they don鈥檛 know about constructors and destructors.

11. free 鎿嶄綔涓嶄細璋冪敤鏋愭瀯鍑芥暟錛屽鏋滄寚閽堟墍鎸囧璞℃湰韜張鍒嗛厤浜嗗唴瀛橈紝鍒欎細閫犳垚鍐呭瓨涓㈠け銆?/span>

Item 4: Prefer C++ style comments

Memory Management

12. Memory management concerns in C++ fall into two general camps: getting it right and making it perform efficiently.

Item 5: Use the same form in corresponding uses of new and delete

13. When you use new, two things happen. First, memory is allocated. Second, one or more constructors are called for that memory. When you use delete, two other things happen: one or more destructors are called for the memory, then the memory is deallocated.

14. The standard C++ library includes string and vector templates that reduce the need for built-in arrays to nearly zero.

Item 6: Use delete on pointer members in destructors

15. Speaking of smart pointers, one way to avoid the need to delete pointer members is to replace those members with smart pointer objects like the standard C++ Library鈥檚 auto_ptr.

Item 7: Be prepared for out-of-memory conditions

Item 8: Adhere to convention when writing operator new and operator delete

Item 9: Avoid hiding the 鈥渘ormal鈥?form of new

Item 10: Write operator delete if you write operator new

璁╂垜浠洖榪囧ご鍘葷湅鐪嬭繖鏍蜂竴涓熀鏈棶棰橈細涓轟粈涔堟湁蹇呰鍐欒嚜宸辯殑 operator new 鍜?/span> operator delete 錛熺瓟妗堥氬父鏄細涓轟簡鏁堢巼銆傜己鐪佺殑 operator new 鍜?/span> operator delete 鍏鋒湁闈炲父濂界殑閫氱敤鎬э紝瀹冪殑榪欑鐏墊椿鎬т篃浣垮緱鍦ㄦ煇浜涚壒瀹氱殑鍦哄悎涓嬶紝鍙互榪涗竴姝ユ敼鍠勫畠鐨勬ц兘銆傚挨鍏跺湪閭d簺闇瑕佸姩鎬佸垎閰嶅ぇ閲忕殑浣嗗緢灝忕殑瀵硅薄鐨勫簲鐢ㄧ▼搴忛噷錛屾儏鍐墊洿鏄姝ゃ?/span>



keyws 2006-08-22 17:24 鍙戣〃璇勮
]]>
銆恘ote銆戙奀++ Primer 錛?8.4鑺傗滃姩鎬佸垎閰嶇殑瀵硅薄鈥濄嬪涔犵瑪璁?http://www.shnenglu.com/keyws/archive/2006/08/22/11573.htmlkeywskeywsTue, 22 Aug 2006 06:54:00 GMThttp://www.shnenglu.com/keyws/archive/2006/08/22/11573.htmlhttp://www.shnenglu.com/keyws/comments/11573.htmlhttp://www.shnenglu.com/keyws/archive/2006/08/22/11573.html#Feedback3http://www.shnenglu.com/keyws/comments/commentRss/11573.htmlhttp://www.shnenglu.com/keyws/services/trackbacks/11573.html
聽聽聽鍔ㄦ佸垎閰嶇殑瀵硅薄錛氱▼搴忓憳瀹屽叏鎺у埗鍒嗛厤涓庨噴鏀撅紝鍒嗛厤鍦ㄧ▼搴忕殑絀洪棽瀛樺偍鍖猴紙free store)鐨勫彲鐢ㄥ唴瀛樻睜涓?span lang="EN-US">

聽1
錛夊崟涓璞$殑鍔ㄦ佸垎閰嶄笌閲婃斁錛?span lang="EN-US">
聽new琛ㄨ揪寮忔病鏈夎繑鍥炲疄闄呭垎閰嶇殑瀵硅薄錛岃屾槸榪斿洖鎸囧悜璇ュ璞$殑鎸囬拡銆傚璇ュ璞$殑鍏ㄩ儴鎿嶄綔閮借閫氳繃榪欎釜鎸囬拡闂存帴瀹屾垚銆?span lang="EN-US">
聽闅忔満鍒嗛厤鐨勫唴瀛樺叿鏈夐殢鏈虹殑浣嶆ā寮忥紝寤鴻鍒濆鍖栵紝渚嬪錛?span lang="EN-US">

聽int* pi = new int(0);


絀洪棽瀛樺偍鍖烘槸鏈夐檺鐨勮祫婧愶紝鑻ヨ鑰楀敖錛?span lang="EN-US">new琛ㄨ揪寮忎細澶辮觸錛屾姏鍑?span lang="EN-US">bad_alloc寮傚父銆?span lang="EN-US">
聽榪欐牱鍋氭病鏈夊繀瑕?span lang="EN-US">:

聽聽聽聽 if 聽(聽pi聽!=聽0聽)
聽聽聽聽聽聽聽聽delete聽pi;

璇存槑錛氬鏋滄寚閽堟搷浣滄暟琚緗負0錛屽垯C++淇濊瘉delete琛ㄨ揪寮忎笉浼氳皟鐢ㄦ搷浣滅delete()銆傛墍浠ユ病鏈夊繀瑕佹祴璇曞叾鏄惁涓?span lang="EN-US">0銆?span lang="EN-US">
聽鍦?span lang="EN-US">delete琛ㄨ揪寮忎箣鍚庯紝pi琚О浣滅┖鎮寚閽堬紝鍗蟲寚鍚戞棤鏁堝唴瀛樼殑鎸囬拡銆傜┖鎮寚閽堟槸紼嬪簭閿欒鐨勬牴婧愶紝寤鴻瀵硅薄閲婃斁鍚庯紝灝嗚鎸囬拡璁劇疆涓?span lang="EN-US">0銆?span lang="EN-US">

聽2錛?span lang="EN-US">auto_ptr
聽auto_ptr鏄?span lang="EN-US">C++鏍囧噯搴撴彁渚涚殑綾繪ā鏉匡紝瀹冨彲浠ュ府鍔╃▼搴忓憳鑷姩綆$悊鐢?span lang="EN-US">new琛ㄨ揪寮忓姩鎬佸垎閰嶇殑鍗曚釜瀵硅薄錛屼絾鏄紝瀹冩病鏈夊鏁扮粍綆$悊鎻愪緵綾諱技鏀寔銆傚畠鐨勫ご鏂囦歡涓猴細

聽聽聽聽#include聽 < memory >

褰?span lang="EN-US">auto_ptr瀵硅薄鐨勭敓鍛芥湡緇撴潫鏃訛紝鍔ㄦ佸垎閰嶇殑瀵硅薄琚嚜鍔ㄩ噴鏀俱?span lang="EN-US">
聽auto_ptr綾繪ā鏉胯儗鍚庣殑涓昏鍔ㄦ満鏄敮鎸佷笌鏅氭寚閽堢被鍨嬬浉鍚岀殑璇硶錛屼絾鏄負auto_ptr瀵硅薄鎵鎸囧璞$殑閲婃斁鎻愪緵鑷姩綆$悊銆備緥錛?span lang="EN-US">

聽聽聽聽 //聽 絎竴縐嶅垵濮嬪寲褰㈠紡
聽聽聽聽std::auto_ptr< int >聽pi(聽 new int (1024)聽);聽聽聽聽 //聽

聽auto_ptr 綾繪ā鏉挎敮鎸佹墍鏈夋潈姒傚康錛屽綋涓涓?span lang="EN-US">auto_ptr瀵硅薄琚敤鍙︿竴涓?span lang="EN-US">auto_ptr瀵硅薄鍒濆鍖栬祴鍊兼椂錛屽乏杈硅璧嬪兼垨鍒濆鍖栫殑瀵硅薄灝辨嫢鏈変簡絀洪棽瀛樺偍鍖哄唴搴曞眰瀵硅薄鐨勬墍鏈夋潈錛岃屽彸杈圭殑auto_ptr瀵硅薄鍒?font color="#ff0000">鎾ゆ秷鎵鏈夎矗浠?/font>銆備緥錛?span lang="EN-US">

聽聽聽聽std::auto_ptr<std:: string >聽pstr_auto(聽 new 聽std:: string (聽"Brontonsaurus"聽)聽);
聽聽聽聽
//聽
絎簩縐嶅垵濮嬪寲褰㈠紡
聽聽聽聽std::auto_ptr<std:: string >聽pstr_auto2(聽pstr_auto聽);

鍒ゆ柇鏄惁鎸囧悜涓涓璞★紝渚嬶細

聽聽聽聽 // 聽絎笁縐嶅垵濮嬪寲褰㈠紡
聽聽聽聽auto_ptr < int > 聽p_auto_int;聽聽聽聽
聽聽聽聽
if 聽(聽p_auto_int. get ()聽 == 0 聽)
聽聽聽聽聽聽聽聽
聽聽聽聽
else
聽聽聽聽聽聽聽聽
// 聽閲嶇疆搴曞眰鎸囬拡錛屽繀欏諱嬌鐢ㄦ鍑芥暟聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽p_auto_int.reset(聽 new int (聽 1024 聽)聽);


聽3錛夋暟緇勭殑鍔ㄦ佸垎閰嶄笌閲婃斁
寤鴻浣跨敤C++鏍囧噯搴?span lang="EN-US">string,
閬垮厤浣跨敤C椋庢牸瀛楃涓叉暟緇勩?span lang="EN-US">
聽涓洪伩鍏嶅姩鎬佸垎閰嶆暟緇勭殑鍐呭瓨綆$悊甯︽潵鐨勯棶棰橈紝涓鑸緩璁嬌鐢ㄦ爣鍑嗗簱vector銆?span lang="EN-US">list鎴?span lang="EN-US">string瀹瑰櫒綾誨瀷銆?span lang="EN-US">

聽4錛夊父閲忓璞$殑鍔ㄦ佸垎閰嶄笌閲婃斁
鍙互浣跨敤new琛ㄨ揪寮忓湪絀洪棽瀛樺偍鍖哄唴鍒涘緩涓涓?span lang="EN-US">const瀵硅薄錛屼緥錛?span lang="EN-US">

聽聽聽聽 //聽 姝ゆ椂蹇呴』鍒濆鍖栵紝鍚﹀垯緙栬瘧閿欒
聽聽聽聽 const int *聽pci聽=聽 new const int (1024);聽聽聽聽

鎴戜滑涓嶈兘鍦ㄧ┖闂插瓨鍌ㄥ尯鍒涘緩鍐呯疆綾誨瀷鍏冪礌鐨?span lang="EN-US">const鏁扮粍錛屽師鍥犳槸錛氭垜浠笉鑳藉垵濮嬪寲鐢?span lang="EN-US">new琛ㄨ揪寮忓垱寤虹殑鍐呯疆綾誨瀷鏁扮粍鐨勫厓绱犮備緥錛?span lang="EN-US">

聽聽聽聽 const int *聽pci聽=聽 new const int [100];聽 //聽 緙栬瘧閿欒


聽5
錛夊畾浣?span lang="EN-US">new琛ㄨ揪寮?span lang="EN-US">
聽new琛ㄨ揪寮忕殑絎笁縐嶅艦寮忓厑璁哥▼搴忓憳瑕佹眰灝嗗璞″垱寤哄湪宸茬粡琚垎閰嶅ソ鐨勫唴瀛樹腑銆傜О涓猴細瀹氫綅new琛ㄨ揪寮忥紙placement new expression)銆傜▼搴忓憳鍦?span lang="EN-US">new琛ㄨ揪寮忎腑鎸囧畾寰呭垱寤哄璞℃墍鍦ㄧ殑鍐呭瓨鍦板潃銆傚涓嬫墍紺猴細
聽new
錛?span lang="EN-US">place_address) type-specifier
聽娉ㄦ剰錛?span lang="EN-US">place_address蹇呴』鏄釜鎸囬拡錛屽繀欏誨寘鍚ご鏂囦歡<new>銆傝繖欏硅鏂藉厑璁哥▼搴忓憳棰勫垎閰嶅ぇ閲忕殑鍐呭瓨錛屼緵浠ュ悗閫氳繃榪欑褰㈠紡鐨?span lang="EN-US">new琛ㄨ揪寮忓垱寤哄璞°備緥濡傦細

聽聽聽聽#include聽 < iostream >
聽聽聽聽#include聽
< new > 聽聽聽聽 // 聽蹇呴』鍖呭惈榪欎釜澶存枃浠?/span>
聽聽聽聽
聽聽聽聽
const int 聽chunk聽 = 16 ;
聽聽聽聽
class 聽Foo
聽聽聽聽
{
聽聽聽聽聽聽聽聽
聽聽聽聽}
;
聽聽聽聽
聽聽聽聽
char * 聽buf聽 = new char [聽 sizeof (Foo)聽 * 聽chunk聽];
聽聽聽聽
聽聽聽聽
int 聽main( int 聽argc,聽 char * 聽argv[])
聽聽聽聽
{
聽聽聽聽聽聽聽聽
// 聽鍙湁榪欑褰㈠紡鐨勫垱寤猴紝娌℃湁閰嶅褰㈠紡鐨刣elete聽
聽聽聽聽聽聽聽聽Foo * 聽pb聽 = new 聽(buf)聽Foo;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽delete[]聽buff;
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽
return 0 ;
聽聽聽聽}



keyws 2006-08-22 14:54 鍙戣〃璇勮
]]>
銆恘ote銆慐ffective C++ (1) - Introduction http://www.shnenglu.com/keyws/archive/2006/08/20/11495.htmlkeywskeywsSun, 20 Aug 2006 08:10:00 GMThttp://www.shnenglu.com/keyws/archive/2006/08/20/11495.htmlhttp://www.shnenglu.com/keyws/comments/11495.htmlhttp://www.shnenglu.com/keyws/archive/2006/08/20/11495.html#Feedback0http://www.shnenglu.com/keyws/comments/commentRss/11495.htmlhttp://www.shnenglu.com/keyws/services/trackbacks/11495.html Introduction

1. A declaration tells compilers about the name and type of an object, function, class, or template, but it omits certain details.

2. A definition, on the other hand, provides compilers with the details. For an object, the definition is where compilers allocate memory for the object. For a function or a function template, the definition provides the code body. For a class or a class template, the definition lists the members of the class or template.

3. When you define a class, you generally need a default constructor if you want to define arrays of objects.Incidentally, if you want to create an array of objects for which there is no default constructor, the usual ploy is to define an array of pointers instead. Then you can initialize each pointer separately by using new.

4. Probably the most important use of the copy constructor is to define what it means to pass and return objects by value.

5. From a purely operational point of view, the difference between initialization and assignment is that the former is performed by a constructor while the latter is performed by operator=. In other words, the two processes correspond to different function calls. The reason for the distinction is that the two kinds of functions must worry about different things. Constructors usually have to check their arguments for validity, whereas most assignment operators can take it for granted that their argument is legitimate (because it has already been constructed). On the other hand, the target of an assignment, unlike an object undergoing construction, may already have resources allocated to it. These resources typically must be released before the new resources can be assigned. Frequently, one of these resources is memory. Before an assignment operator can allocate memory for a new value, it must first deallocate the memory that was allocated for the old value.

// 聽a聽possible聽String聽constructor
String::String( const char * value)
{
聽聽聽聽
if 聽(value)
聽聽聽聽
{聽
聽聽聽聽聽聽聽聽
// 聽if聽value聽ptr聽isn't聽null
聽聽聽聽聽聽聽聽data聽 = new char [strlen(value)聽 + 1 ];
聽聽聽聽聽聽聽聽strcpy(data,value);
聽聽聽聽}
聽聽聽聽
聽聽聽聽
else
聽聽聽聽
{聽
聽聽聽聽聽聽聽聽
// 聽handle聽null聽value聽ptr3
聽聽聽聽聽聽聽聽data聽 = new char [ 1 ];
聽聽聽聽聽聽聽聽
* data聽 = ' \0 ' ;聽 // 聽add聽trailing
聽聽聽聽聽聽聽聽 null char
聽聽聽聽}

}


// 聽a聽possible聽String聽assignment聽operator

String
& 聽String:: operator = ( const 聽String & 聽rhs)
{
聽聽聽聽
if 聽( this == & rhs)
聽聽聽聽聽聽聽聽
return * this ;聽 // 聽see聽Item聽17

聽聽聽聽delete聽[]聽data;聽
// 聽delete聽old聽memory
聽聽聽聽
聽聽聽聽data聽
= // 聽allocate聽new聽memory
聽聽聽聽聽聽聽聽 new char [strlen(rhs.data)聽 + 1 ];

聽聽聽聽strcpy(data,聽rhs.data);
聽聽聽聽
聽聽聽聽
return * this ;聽 // 聽see聽Item聽15
}


6. These different casting forms serve different purposes:

const_cast is designed to cast away the constness of objects and pointers, a topic I examine in Item 21.

dynamic_cast is used to perform "safe downcasting," a subject we'll explore in Item 39.

reinterpret_cast is engineered for casts that yield implementation-dependent results, e.g., casting between function pointer types. (You're not likely to need reinterpret_cast very often. I don't use it at all in this book.)

static_cast is sort of the catch-all cast. It's what you use when none of the other casts is appropriate. It's the closest in meaning to the conventional C-style casts.



keyws 2006-08-20 16:10 鍙戣〃璇勮
]]>
銆愯漿銆慜perator Overloadinghttp://www.shnenglu.com/keyws/archive/2006/08/17/11335.htmlkeywskeywsThu, 17 Aug 2006 04:14:00 GMThttp://www.shnenglu.com/keyws/archive/2006/08/17/11335.htmlhttp://www.shnenglu.com/keyws/comments/11335.htmlhttp://www.shnenglu.com/keyws/archive/2006/08/17/11335.html#Feedback0http://www.shnenglu.com/keyws/comments/commentRss/11335.htmlhttp://www.shnenglu.com/keyws/services/trackbacks/11335.html闃呰鍏ㄦ枃

keyws 2006-08-17 12:14 鍙戣〃璇勮
]]>
銆愬師銆戣繍綆楃閲嶈澆涓庡悕瀛楃┖闂寸殑鍥版儜http://www.shnenglu.com/keyws/archive/2006/08/16/11304.htmlkeywskeywsWed, 16 Aug 2006 13:09:00 GMThttp://www.shnenglu.com/keyws/archive/2006/08/16/11304.htmlhttp://www.shnenglu.com/keyws/comments/11304.htmlhttp://www.shnenglu.com/keyws/archive/2006/08/16/11304.html#Feedback0http://www.shnenglu.com/keyws/comments/commentRss/11304.htmlhttp://www.shnenglu.com/keyws/services/trackbacks/11304.html 聽聽聽瀛︿範鏁版嵁緇撴瀯錛岀敤鍒頒簡杈撳叆杈撳嚭榪愮畻絎﹂噸杞斤紝緇撴灉緙栬瘧涔嬩笅錛岄敊璇噸閲嶏紝錛岄殢鍗沖仠姝㈠涔犺繘搴︼紝榪芥煡紲告簮錛屽湪鑺辮垂宸ㄥぇ鑴戝姏涓庢椂闂存垚鏈箣鍚庯紝緇堜簬鐭ヨ嚜宸遍敊璇箣鎵鍦紝瀹氫綅浜庡悕瀛楃┖闂翠箣鍥版壈銆備負鐗㈣鏁欒錛屽啓涓綆鍖栫増鏈褰?/span> debug 榪囩▼濡備笅錛岃紺鴻嚜宸便?br />

闂錛?br />聽聽聽

聽聽聽鏈夊涓嬩袱涓唬鐮佹枃浠訛細
聽聽聽// 20060816_operator.cxx

聽1#include聽<iostream>
聽2usingnamespace聽std;
聽3#include聽"20060816_operator.h"
聽4int聽main(int聽argc,聽char*聽argv[])
聽5{
聽6聽聽聽聽const聽std::string聽GHH("GuoHonghua");
聽7聽聽聽聽Honghua聽ghh(GHH);
聽8聽聽聽聽cout聽<<聽ghh聽<<聽endl;
聽9聽聽聽聽return0;
10}
聽聽聽

// 20060816_operator.h

聽1#ifndef聽_20060816_OPERATOR_GHH_
聽2#define聽_20060816_OPERATOR_GHH_聽聽聽聽1
聽3
聽4//聽Author聽:聽GuoHonghua
聽5//聽Date聽:聽2006.08.16
聽6//聽File聽:聽20060816_operator.h
聽7
聽8#include聽<iostream>
聽9#include聽<string>
10class聽Honghua
11{
12聽聽聽聽friend聽std::ostream&operator<<(std::ostream&聽os,聽const聽Honghua&聽ghh);
13public:
14聽聽聽聽Honghua(const聽std::string&聽ghh)聽:聽_ghh(ghh)
15聽聽聽聽{
16聽聽聽聽}
17
18private:
19聽聽聽聽std::string聽_ghh;
20};
21
22std::ostream&operator<<(std::ostream&聽os,聽const聽Honghua&聽ghh)
23{
24聽聽聽聽os聽<<聽ghh._ghh;
25聽聽聽聽return聽os;
26}
27
28#endif//聽end聽of聽_20060816_OPERATOR_GHH_

鐢ㄤ笂闈袱涓枃浠跺緩绔嬪伐紼嬶紝vc6.0涓嬬紪璇戜細鍑洪敊銆傛姤鍛婂涓嬶細

--------------------Configuration: 20060816_operator - Win32 Debug--------------------

Compiling...

20060816_operator.cxx

f:\ghh_project\cxxdetail\20060816_operator.h(24) : error C2248: '_ghh' : cannot access private member declared in class 'Honghua'

聽聽聽聽聽聽聽 f:\ghh_project\cxxdetail\20060816_operator.h(19) : see declaration of '_ghh'

F:\ghh_project\CxxDetail\20060816_operator.cxx(8) : error C2593: 'operator <<' is ambiguous

Error executing cl.exe.

20060816_operator.exe - 2 error(s), 0 warning(s)
瑙e喅:
聽聽聽

1錛?span style="FONT: 7pt 'Times New Roman'">聽 璋冩暣鍚嶅瓧絀洪棿澹版槑鍜岃嚜瀹氫箟澶存枃浠剁殑嬈″簭錛屽涓嬶細

1#include聽<iostream>
2#include聽"20060816_operator.h"
3usingnamespace聽std;
4int聽main(int聽argc,聽char*聽argv[])
5

2錛?span style="FONT: 7pt 'Times New Roman'">聽 鎶婄被瀹氫箟浜庢爣鍑嗗悕瀛椾箣鍐咃紝20060816_operator.h鏂囦歡淇敼濡備笅錛堜笉鎺ㄨ崘錛?br />

聽1#ifndef聽_20060816_OPERATOR_GHH_
聽2#define聽_20060816_OPERATOR_GHH_聽聽聽聽1
聽3
聽4//聽Author聽:聽GuoHonghua
聽5//聽Date聽:聽2006.08.16
聽6//聽File聽:聽20060816_operator.h
聽7
聽8#include聽<iostream>
聽9#include聽<string>
10namespace聽std
11{
12聽聽聽聽class聽Honghua
13聽聽聽聽{
14聽聽聽聽聽聽聽聽friend聽std::ostream&operator<<(std::ostream&聽os,聽const聽Honghua&聽ghh);
15聽聽聽聽public:
16聽聽聽聽聽聽聽聽Honghua(const聽std::string&聽ghh)聽:聽_ghh(ghh)
17聽聽聽聽聽聽聽聽{
18聽聽聽聽聽聽聽聽}
19聽聽聽聽聽聽聽聽
20聽聽聽聽private:
21聽聽聽聽聽聽聽聽std::string聽_ghh;
22聽聽聽聽};
23聽聽聽聽
24聽聽聽聽
25聽聽聽聽std::ostream&operator<<(std::ostream&聽os,聽const聽Honghua&聽ghh)
26聽聽聽聽{
27聽聽聽聽聽聽聽聽os聽<<聽ghh._ghh;
28聽聽聽聽聽聽聽聽return聽os;
29聽聽聽聽}
30}
31#endif//聽end聽of聽_20060816_OPERATOR_GHH_

3錛?span style="FONT: 7pt 'Times New Roman'">聽 浣跨敤澶存枃浠?/span>iostream.h浠f浛iostream,姣旇緝钀藉悗鐨勬柟寮忥紙涓嶆帹鑽?/span>!錛?br />

聽1//聽20060816_operator.cxx
聽2//聽#include聽<iostream>
聽3#include聽<iostream.h>
聽4#include聽<iostream.h>
聽5#include聽"20060816_operator.h"
聽6int聽main(int聽argc,聽char*聽argv[])
聽7{
聽8聽聽聽聽const聽std::string聽GHH("GuoHonghua");
聽9聽聽聽聽Honghua聽ghh(GHH);
10聽聽聽聽cout聽<<聽ghh聽<<聽endl;
11聽聽聽聽return0;
12}

聽1//聽20060816_operator.h
聽2#ifndef聽_20060816_OPERATOR_GHH_
聽3#define聽_20060816_OPERATOR_GHH_聽聽聽聽1
聽4
聽5//聽Author聽:聽GuoHonghua
聽6//聽Date聽:聽2006.08.16
聽7//聽File聽:聽20060816_operator.h
聽8//聽#include聽<iostream>
聽9#include聽<iostream.h>
10#include聽<string>
11
12class聽Honghua
13{
14聽聽聽聽friend聽ostream&operator<<(ostream&聽os,聽const聽Honghua&聽ghh);
15public:
16聽聽聽聽Honghua(const聽std::string&聽ghh)聽:聽_ghh(ghh)
17聽聽聽聽{
18聽聽聽聽}
19聽聽聽聽
20private:
21聽聽聽聽std::string聽_ghh;
22};
23
24
25ostream&operator<<(ostream&聽os,聽const聽Honghua&聽ghh)
26{
27聽聽聽聽os聽<<聽ghh._ghh;
28聽聽聽聽return聽os;
29}
30
31#endif//聽end聽of聽_20060816_OPERATOR_GHH_

4錛?span style="FONT: 7pt 'Times New Roman'">聽 浠諱綍鏃跺欓兘涓嶄嬌鐢?/span>using namespace 澹版槑錛佽繖鏄彧闇瑕佷慨鏀?/span>20060816_operator.cxx鏂囦歡濡備笅錛?br />

聽1#include聽<iostream>
聽2#include聽"20060816_operator.h"
聽3int聽main(int聽argc,聽char*聽argv[])
聽4{
聽5聽聽聽聽//聽const聽string聽GHH("GuoHonghua");
聽6聽聽聽聽const聽std::string聽GHH("GuoHonghua");
聽7聽聽聽聽Honghua聽ghh(GHH);
聽8聽聽聽聽//聽cout聽<<聽ghh聽<<聽endl;
聽9聽聽聽聽std::cout聽<<聽ghh聽<<聽std::endl;
10聽聽聽聽return0;
11}

浣撲細錛?br />聽聽聽鍚嶅瓧絀洪棿鏈潵灝辨槸涓轟簡瑙e喅鍚嶅瓧鍐茬獊闂鑰屽紩鍏ワ紝浠ヤ嬌鏍囧噯搴撲笉鍙楀鐣屽獎鍝嶃傚湪榪欎釜鎰忎箟涓婃潵璇達紝using namespace std;涓嶆槸鍙互闅忔剰浣跨敤鐨勮鍙ワ紝搴旇鑰冭檻鍒板畠鐨勪綅緗紼嬪簭鐨勫彲鑳藉獎鍝嶏紝鑰屾渶褰誨簳鐨勬潨緇濋敊璇殑瑙e喅鍔炴硶鏄湪浠諱綍鏃跺欎換浣曟儏鍐典笅閮戒笉浣跨敤姝よ鍙ワ紒



keyws 2006-08-16 21:09 鍙戣〃璇勮
]]>
銆愯漿銆憊ector 錛堜簩錛?/title><link>http://www.shnenglu.com/keyws/archive/2006/08/13/11194.html</link><dc:creator>keyws</dc:creator><author>keyws</author><pubDate>Sun, 13 Aug 2006 11:52:00 GMT</pubDate><guid>http://www.shnenglu.com/keyws/archive/2006/08/13/11194.html</guid><wfw:comment>http://www.shnenglu.com/keyws/comments/11194.html</wfw:comment><comments>http://www.shnenglu.com/keyws/archive/2006/08/13/11194.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/keyws/comments/commentRss/11194.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/keyws/services/trackbacks/11194.html</trackback:ping><description><![CDATA[ <table> <tbody> <tr> <td> <div id="xbfhppp" class="body-content"> <div id="zvbvffd" class="header-box"> <a >www.cppreference.com</a> <br /> <br />assign </div> <div id="vnrzbhn" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">1</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">2</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">聽assign(聽size_type聽num,聽</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">聽TYPE</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">聽val聽);<br /></span><span style="COLOR: #008080">3</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">聽assign(聽input_iterator聽start,聽input_iterator聽end聽);</span></div> </pre> <p>The assign() function either gives the current vector the values from <em>start</em> to <em>end</em>, or gives it <em>num</em> copies of <em>val</em>.</p> <p>This function <font color="#ff3333">will destroy the previous contents of the vector.</font></p> <p>For example, the following code uses assign() to put 10 copies of the integer 42 into a vector:</p> <pre class="example-code"> vector<int> v; v.assign( 10, 42 ); for( int i = 0; i < v.size(); i++ ) { cout << v[i] << " "; } cout << endl; </pre> <p>The above code displays the following output:</p> <pre class="example-code"> 42 42 42 42 42 42 42 42 42 42 </pre> <p>The next example shows how assign() can be used to copy one vector to another:</p> <pre class="example-code"> vector<int> v1; for( int i = 0; i < 10; i++ ) { v1.push_back( i ); } vector<int> v2; v2.assign( v1.begin(), v1.end() ); for( int i = 0; i < v2.size(); i++ ) { cout << v2[i] << " "; } cout << endl; </pre> <p>When run, the above code displays the following output:</p> <pre class="example-code"> 0 1 2 3 4 5 6 7 8 9</pre> </div> </td> </tr> </tbody> </table> <hr /> <div id="ltvzdtj" class="name-format">back </div> <div id="xrdpzhn" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">1</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">2</span>聽<span style="COLOR: #000000">TYPE</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">聽back();<br /></span><span style="COLOR: #008080">3</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">聽TYPE</span><span style="COLOR: #000000">&</span><span style="COLOR: #000000">聽back()聽</span><span style="COLOR: #0000ff">const</span><span style="COLOR: #000000">;</span></div> </pre> <p>The back() function <font color="#ff3300">returns a reference to the last element in the vector</font>.</p> <p>For example:</p> <pre class="example-code"> vector<int> v; for( int i = 0; i < 5; i++ ) { v.push_back(i); } cout << "The first element is " << v.front() << " and the last element is " << v.back() << endl; </pre> <p>This code produces the following output:</p> <pre class="example-code"> The first element is 0 and the last element is 4 </pre> <p> </p> <hr /> <p> </p> <div id="vfhbfnl" class="name-format">at </div> <div id="rbxrbbh" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> <a >TYPE</a>& at( <strong>size_type</strong> loc ); const <a >TYPE</a>& at( <strong>size_type</strong> loc ) const; </pre> <p>The at() function<font color="#ff3300"> returns a reference to the element in the vector at index <em>loc</em></font>. The at() function is safer than the [] operator, because it won't let you reference items outside the bounds of the vector.</p> <p>For example, consider the following code:</p> <pre class="example-code"> vector<int> v( 5, 1 ); for( int i = 0; i < 10; i++ ) { cout << "Element " << i << " is " << v[i] << endl; } </pre> <p>This code overrunns the end of the vector, producing potentially dangerous results. The following code would be much safer:</p> <pre class="example-code"> vector<int> v( 5, 1 ); for( int i = 0; i < 10; i++ ) { cout << "Element " << i << " is " << v.at(i) << endl; } </pre> <p>Instead of attempting to read garbage values from memory, the at() function will realize that it is about to overrun the vector and will throw an exception.</p> <div id="tfbnxfx" class="related-name-format"> <hr /> </div> <div id="xjbvrpn" class="name-format">capacity </div> <div id="tlxhlrz" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> <strong>size_type</strong> capacity() const; </pre> <p>The capacity() function <font color="#ff3333">returns the number of elements that the vector can hold before it will need to allocate more space</font>.</p> <p>For example, the following code uses two different methods to set the capacity of two vectors. One method passes an argument to the constructor that suggests an initial size, the other method calls the reserve function to achieve a similar goal:</p> <pre class="example-code"> vector<int> v1(10); cout << "The capacity of v1 is " << v1.capacity() << endl; vector<int> v2; v2.reserve(20); cout << "The capacity of v2 is " << v2.capacity() << endl; </pre> <p>When run, the above code produces the following output:</p> <pre class="example-code"> The capacity of v1 is 10 The capacity of v2 is 20 </pre> <p>C++ containers are designed to grow in size dynamically. This frees the programmer from having to worry about storing an arbitrary number of elements in a container. However, sometimes the programmer can improve the performance of her program by giving hints to the compiler about the size of the containers that the program will use. These hints come in the form of the <a >reserve</a>() function and the constructor used in the above example, which tell the compiler how large the container is expected to get.</p> <p>The capacity() function runs in <a >constant time</a>.</p> <div> </div> <hr /> <div id="lpjlfll" class="name-format">begin </div> <div id="dhlvhfv" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> iterator begin(); const_iterator begin() const; </pre> <p>The function begin() returns an iterator to the first element of the vector. begin() should run in <a >constant time</a>.</p> <p>For example, the following code uses begin() to initialize an iterator that is used to traverse a list:</p> <pre class="example-code"> // Create a list of characters list<char> charList; for( int i=0; i < 10; i++ ) { charList.push_front( i + 65 ); } // Display the list list<char>::iterator theIterator; for( theIterator = charList.begin(); theIterator != charList.end(); theIterator++ ) { cout << *theIterator; } </pre> <div id="fhbnppp" class="related-name-format"> <hr /> </div> <div id="vpznppd" class="name-format">max_size </div> <div id="hjnhrjz" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> <strong>size_type</strong> max_size() const; </pre> <p>The max_size() function returns the maximum number of elements that the vector can hold. The max_size() function should not be confused with the <a >size</a>() or <a >capacity</a>() functions, which return the number of elements currently in the vector and the the number of elements that the vector will be able to hold before more memory will have to be allocated, respectively.</p> <div id="hjfrlrb" class="related-name-format"> <hr /> </div> <div id="xzjvzzh" class="name-format">clear </div> <div id="vnhtnfl" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> void clear(); </pre> <p>The function clear() deletes all of the elements in the vector. clear() runs in <a >linear time</a>.</p> <div id="hzbnzhf" class="related-name-format"> <hr /> </div> <div id="htdhlbj" class="name-format">empty </div> <div id="nxhbfdl" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> bool empty() const; </pre> <p>The empty() function returns true if the vector has no elements, false otherwise.</p> <p>For example, the following code uses empty() as the stopping condition on a (C/C++ Keywords) <a >while</a> loop to clear a vector and display its contents in reverse order:</p> <pre class="example-code"> vector<int> v; for( int i = 0; i < 5; i++ ) { v.push_back(i); } while( !v.empty() ) { cout << v.back() << endl; v.pop_back(); } </pre> <div id="dfbtnft" class="related-name-format"> <hr /> </div> <div id="hzdfhpv" class="name-format">end </div> <div id="fhbdpfl" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> iterator end(); const_iterator end() const; </pre> <p>The end() function returns an iterator just past the end of the vector.</p> <p>Note that before you can access the last element of the vector using an iterator that you get from a call to end(), you'll have to decrement the iterator first. This is because end() doesn't point to the end of the vector; it points <strong>just past the end of the vector</strong>.</p> <p>For example, in the following code, the first "cout" statement will display garbage, whereas the second statement will actually display the last element of the vector:</p> <pre class="example-code"> vector<int> v1; v1.push_back( 0 ); v1.push_back( 1 ); v1.push_back( 2 ); v1.push_back( 3 ); int bad_val = *(v1.end()); cout << "bad_val is " << bad_val << endl; int good_val = *(v1.end() - 1); cout << "good_val is " << good_val << endl; </pre> <p>The next example shows how <a >begin</a>() and end() can be used to iterate through all of the members of a vector:</p> <pre class="example-code"> vector<int> v1( 5, 789 ); vector<int>::iterator it; for( it = v1.begin(); it != v1.end(); it++ ) { cout << *it << endl; } </pre> <p>The iterator is initialized with a call to <a >begin</a>(). After the body of the loop has been executed, the iterator is incremented and tested to see if it is equal to the result of calling end(). Since end() returns an iterator pointing to an element just after the last element of the vector, the loop will only stop once all of the elements of the vector have been displayed.</p> <p>end() runs in <a >constant time</a>.<br /><br /></p> <hr /> <div id="zrvxrhf" class="name-format">erase </div> <div id="vrlvpnd" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> iterator erase( iterator loc ); iterator erase( iterator start, iterator end ); </pre> <p>The erase() function either deletes the element at location <em>loc</em>, or deletes the elements between <em>start</em> and <em>end</em> (including <em>start</em> but not including <em>end</em>). The return value is the element after the last element erased.</p> <p>The first version of erase (the version that deletes a single element at location <em>loc</em>) runs in <a >constant time</a> for lists and <a >linear time</a> for vectors, dequeues, and strings. The multiple-element version of erase always takes <a >linear time</a>.</p> <p>For example:</p> <pre class="example-code"> // Create a vector, load it with the first ten characters of the alphabet vector<char> alphaVector; for( int i=0; i < 10; i++ ) { alphaVector.push_back( i + 65 ); } int size = alphaVector.size(); vector<char>::iterator startIterator; vector<char>::iterator tempIterator; for( int i=0; i < size; i++ ) { startIterator = alphaVector.begin(); alphaVector.erase( startIterator ); // Display the vector for( tempIterator = alphaVector.begin(); tempIterator != alphaVector.end(); tempIterator++ ) { cout << *tempIterator; } cout << endl; } </pre> <p>That code would display the following output:</p> <pre class="example-code"> BCDEFGHIJ CDEFGHIJ DEFGHIJ EFGHIJ FGHIJ GHIJ HIJ IJ J </pre> <p>In the next example, erase() is called with two iterators to delete a range of elements from a vector:</p> <pre class="example-code"> // create a vector, load it with the first ten characters of the alphabet vector<char> alphaVector; for( int i=0; i < 10; i++ ) { alphaVector.push_back( i + 65 ); } // display the complete vector for( int i = 0; i < alphaVector.size(); i++ ) { cout << alphaVector[i]; } cout << endl; // use erase to remove all but the first two and last three elements // of the vector alphaVector.erase( alphaVector.begin()+2, alphaVector.end()-3 ); // display the modified vector for( int i = 0; i < alphaVector.size(); i++ ) { cout << alphaVector[i]; } cout << endl; </pre> <p>When run, the above code displays:</p> <pre class="example-code"> ABCDEFGHIJ ABHIJ </pre> <div id="jtfjllz" class="related-name-format">Related topics: </div> <div id="bdhjdbb" class="related-content"> <a >clear</a> <br /> <a >insert</a> <br /> <a >pop_back</a> <br />(C++ Lists) <a >pop_front</a><br />(C++ Lists) <a >remove</a><br />(C++ Lists) <a >remove_if</a></div> <div> </div> <hr /> <div id="jlxdflt" class="name-format">front </div> <div id="hjlhzrp" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> <a >TYPE</a>& front(); const <a >TYPE</a>& front() const; </pre> <p>The front() function returns a reference to the first element of the vector, and runs in <a >constant time</a>.</p> <div id="nxbdhnn" class="related-name-format">Related topics: </div> <div id="dfrtxvn" class="related-content"> <a >back</a> <br />(C++ Lists) <a >pop_front</a><br />(C++ Lists) <a >push_front</a></div> <div> </div> <hr /> <div id="lnpjvvt" class="name-format">insert </div> <div id="tvztlbj" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> iterator insert( iterator loc, const <a >TYPE</a>& val ); void insert( iterator loc, <strong>size_type</strong> num, const <a >TYPE</a>& val ); template<<a >TYPE</a>> void insert( iterator loc, <a >input_iterator</a> start, <a >input_iterator</a> end ); </pre> <p>The insert() function either:</p> <ul> <li>inserts <em>val</em> before <em>loc</em>, returning an iterator to the element inserted, </li> <li>inserts <em>num</em> copies of <em>val</em> before <em>loc</em>, or </li> <li>inserts the elements from <em>start</em> to <em>end</em> before <em>loc</em>. </li> </ul> <p>Note that inserting elements into a vector can be relatively time-intensive, since the underlying data structure for a vector is an array. In order to insert data into an array, you might need to displace a lot of the elements of that array, and this can take <a >linear time</a>. If you are planning on doing a lot of insertions into your vector and you care about speed, you might be better off using a container that has a linked list as its underlying data structure (such as a <a >List</a> or a <a >Deque</a>).</p> <p>For example, the following code uses the insert() function to splice four copies of the character 'C' into a vector of characters:</p> <pre class="example-code"> // Create a vector, load it with the first 10 characters of the alphabet vector<char> alphaVector; for( int i=0; i < 10; i++ ) { alphaVector.push_back( i + 65 ); } // Insert four C's into the vector vector<char>::iterator theIterator = alphaVector.begin(); alphaVector.insert( theIterator, 4, 'C' ); // Display the vector for( theIterator = alphaVector.begin(); theIterator != alphaVector.end(); theIterator++ ) { cout << *theIterator; } </pre> <p>This code would display:</p> <pre class="example-code"> CCCCABCDEFGHIJ </pre> <p>Here is another example of the insert() function. In this code, insert() is used to append the contents of one vector onto the end of another:</p> <pre class="example-code"> vector<int> v1; v1.push_back( 0 ); v1.push_back( 1 ); v1.push_back( 2 ); v1.push_back( 3 ); vector<int> v2; v2.push_back( 5 ); v2.push_back( 6 ); v2.push_back( 7 ); v2.push_back( 8 ); cout << "Before, v2 is: "; for( int i = 0; i < v2.size(); i++ ) { cout << v2[i] << " "; } cout << endl; v2.insert( v2.end(), v1.begin(), v1.end() ); cout << "After, v2 is: "; for( int i = 0; i < v2.size(); i++ ) { cout << v2[i] << " "; } cout << endl; </pre> <p>When run, this code displays:</p> <pre class="example-code"> Before, v2 is: 5 6 7 8 After, v2 is: 5 6 7 8 0 1 2 3 </pre> <div id="vfhdfdt" class="related-name-format">Related topics: </div> <div id="tdnzttj" class="related-content"> <a >assign</a> <br /> <a >erase</a> <br /> <a >push_back</a> <br />(C++ Lists) <a >merge</a><br />(C++ Lists) <a >push_front</a><br />(C++ Lists) <a >splice</a></div> <div> </div> <hr /> <div id="nnrdxfn" class="name-format">Vector constructors </div> <div id="tvprddt" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> vector(); vector( const vector& c ); vector( <strong>size_type</strong> num, const <a >TYPE</a>& val = <a >TYPE</a>() ); vector( <a >input_iterator</a> start, <a >input_iterator</a> end ); ~vector(); </pre> <p>The default vector constructor takes no arguments, creates a new instance of that vector.</p> <p>The second constructor is a default copy constructor that can be used to create a new vector that is a copy of the given vector <em>c</em>.</p> <p>The third constructor creates a vector with space for <em>num</em> objects. If <em>val</em> is specified, each of those objects will be given that value. For example, the following code creates a vector consisting of five copies of the integer 42:</p> <pre class="example-code"> vector<int> v1( 5, 42 ); </pre> <p>The last constructor creates a vector that is initialized to contain the elements between <em>start</em> and <em>end</em>. For example:</p> <pre class="example-code"> // create a vector of random integers cout << "original vector: "; vector<int> v; for( int i = 0; i < 10; i++ ) { int num = (int) rand() % 10; cout << num << " "; v.push_back( num ); } cout << endl; // find the first element of v that is even vector<int>::iterator iter1 = v.begin(); while( iter1 != v.end() && *iter1 % 2 != 0 ) { iter1++; } // find the last element of v that is even vector<int>::iterator iter2 = v.end(); do { iter2--; } while( iter2 != v.begin() && *iter2 % 2 != 0 ); cout << "first even number: " << *iter1 << ", last even number: " << *iter2 << endl; cout << "new vector: "; vector<int> v2( iter1, iter2 ); for( int i = 0; i < v2.size(); i++ ) { cout << v2[i] << " "; } cout << endl; </pre> <p>When run, this code displays the following output:</p> <pre class="example-code"> original vector: 1 9 7 9 2 7 2 1 9 8 first even number: 2, last even number: 8 new vector: 2 7 2 1 9 </pre> <p>All of these constructors run in <a >linear time</a> except the first, which runs in <a >constant time</a>.</p> <p>The default destructor is called when the vector should be destroyed.</p> <div> </div> <hr /> <div id="vpjnpfl" class="name-format">pop_back </div> <div id="vvzdvdt" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> void pop_back(); </pre> <p>The pop_back() function removes the last element of the vector.</p> <p>pop_back() runs in <a >constant time</a>.</p> <div id="xhlvpvd" class="related-name-format">Related topics: </div> <div id="fhbvpfl" class="related-content"> <a >back</a> <br /> <a >erase</a> <br />(C++ Lists) <a >pop_front</a><br /><a >push_back</a></div> <div> </div> <hr /> <div id="fpbpzxf" class="name-format">push_back </div> <div id="hjlfrhx" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> void push_back( const <a >TYPE</a>& val ); </pre> <p>The push_back() function appends <em>val</em> to the end of the vector.</p> <p>For example, the following code puts 10 integers into a list:</p> <pre class="example-code"> list<int> the_list; for( int i = 0; i < 10; i++ ) the_list.push_back( i ); </pre> <p>When displayed, the resulting list would look like this:</p> <pre class="example-code"> 0 1 2 3 4 5 6 7 8 9 </pre> <p>push_back() runs in <a >constant time</a>.</p> <div id="llfrdbz" class="related-name-format">Related topics: </div> <div id="rtnzljh" class="related-content"> <a >assign</a> <br /> <a >insert</a> <br /> <a >pop_back</a> <br />(C++ Lists) <a >push_front</a></div> <div> </div> <hr /> <div id="bnpjdtr" class="name-format">rbegin </div> <div id="tvfzltb" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> <a >reverse_iterator</a> rbegin(); const_<a >reverse_iterator</a> rbegin() const; </pre> <p>The rbegin() function returns a <a >reverse_iterator</a> to the end of the current vector.</p> <p>rbegin() runs in <a >constant time</a>.</p> <div id="pjdxjxx" class="related-name-format">Related topics: </div> <div id="ftblpnv" class="related-content"> <a >begin</a> <br /> <a >end</a> <br /> <a >rend</a> </div> <div> </div> <hr /> <div id="xxrtvnd" class="name-format">rend </div> <div id="hjlvhfn" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> <a >reverse_iterator</a> rend(); const_<a >reverse_iterator</a> rend() const; </pre> <p>The function rend() returns a <a >reverse_iterator</a> to the beginning of the current vector.</p> <p>rend() runs in <a >constant time</a>.</p> <div id="ldptflb" class="related-name-format">Related topics: </div> <div id="pxbfpxv" class="related-content"> <a >begin</a> <br /> <a >end</a> <br /> <a >rbegin</a> </div> <div> </div> <hr /> <div id="pzvnzzp" class="name-format">reserve </div> <div id="frjnrfn" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> void reserve( <strong>size_type</strong> size ); </pre> <p>The reserve() function sets the capacity of the vector to at least <em>size</em>.</p> <p>reserve() runs in <a >linear time</a>.</p> <div id="zjbxhpv" class="related-name-format">Related topics: </div> <div id="dfhdnvv" class="related-content"> <a >capacity</a> </div> <div> </div> <hr /> <div id="zbdpjzf" class="name-format">resize </div> <div id="lhlvzhx" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> void resize( <strong>size_type</strong> num, const <a >TYPE</a>& val = <a >TYPE</a>() ); </pre> <p>The function resize() changes the size of the vector to <em>size</em>. If <em>val</em> is specified then any newly-created elements will be initialized to have a value of <em>val</em>.</p> <p>This function runs in <a >linear time</a>.</p> <div id="nfjvpft" class="related-name-format">Related topics: </div> <div id="tdhjfdb" class="related-content"> <a >Vector constructors & destructors</a> <br /> <a >capacity</a> <br /> <a >size</a> </div> <div> </div> <hr /> <div id="npjtdbr" class="name-format">size </div> <div id="dvprddb" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> <strong>size_type</strong> size() const; </pre> <p>The size() function returns the number of elements in the current vector.</p> <div id="tvrbxlb" class="related-name-format">Related topics: </div> <div id="xzvxrpp" class="related-content"> <a >capacity</a> <br /> <a >empty</a> <br />(C++ Strings) <a >length</a><br /><a >max_size</a><br /><a >resize</a></div> <div> </div> <hr /> <div id="hlnhtbt" class="name-format">swap </div> <div id="vfrnxxl" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> void swap( const container& from ); </pre> <p>The swap() function exchanges the elements of the current vector with those of <em>from</em>. This function operates in <a >constant time</a>.</p> <p>For example, the following code uses the swap() function to exchange the values of two strings:</p> <pre class="example-code"> string first( "This comes first" ); string second( "And this is second" ); first.swap( second ); cout << first << endl; cout << second << endl; </pre> <p>The above code displays:</p> <pre class="example-code"> And this is second This comes first </pre> <div id="xhjfpvd" class="related-name-format">Related topics: </div> <div id="xhtnhpn" class="related-content">(C++ Lists) <a >splice</a></div> <div> </div> <hr /> <div id="prbxjzx" class="name-format">Vector operators </div> <div id="vfrnhxl" class="syntax-name-format">Syntax: </div> <pre class="syntax-box"> #include <vector> <a >TYPE</a>& operator[]( <strong>size_type</strong> index ); const <a >TYPE</a>& operator[]( <strong>size_type</strong> index ) const; vector operator=(const vector& c2); bool operator==(const vector& c1, const vector& c2); bool operator!=(const vector& c1, const vector& c2); bool operator<(const vector& c1, const vector& c2); bool operator>(const vector& c1, const vector& c2); bool operator<=(const vector& c1, const vector& c2); bool operator>=(const vector& c1, const vector& c2); </pre> <p>All of the C++ containers can be compared and assigned with the standard comparison operators: ==, !=, <=, >=, <, >, and =. Individual elements of a vector can be examined with the [] operator.</p> <p>Performing a comparison or assigning one vector to another takes <a >linear time</a>. The [] operator runs in <a >constant time</a>.</p> <p>Two vectors are equal if:</p> <ol> <li>Their size is the same, and </li> <li>Each member in location i in one vector is equal to the the member in location i in the other vector. </li> </ol> <p>Comparisons among vectors are done lexicographically.</p> <p>For example, the following code uses the [] operator to access all of the elements of a vector:</p> <pre class="example-code"> vector<int> v( 5, 1 ); for( int i = 0; i < v.size(); i++ ) { cout << "Element " << i << " is " << v[i] << endl; } </pre> <div id="dnfjbzp" class="related-name-format">Related topics: </div> <div id="hlnzrhh" class="related-content"> <a >at</a> </div> <div> </div> <hr /> <img src ="http://www.shnenglu.com/keyws/aggbug/11194.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/keyws/" target="_blank">keyws</a> 2006-08-13 19:52 <a href="http://www.shnenglu.com/keyws/archive/2006/08/13/11194.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>銆愯漿銆憊ector錛堜竴錛?/title><link>http://www.shnenglu.com/keyws/archive/2006/08/13/11193.html</link><dc:creator>keyws</dc:creator><author>keyws</author><pubDate>Sun, 13 Aug 2006 11:36:00 GMT</pubDate><guid>http://www.shnenglu.com/keyws/archive/2006/08/13/11193.html</guid><wfw:comment>http://www.shnenglu.com/keyws/comments/11193.html</wfw:comment><comments>http://www.shnenglu.com/keyws/archive/2006/08/13/11193.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/keyws/comments/commentRss/11193.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/keyws/services/trackbacks/11193.html</trackback:ping><description><![CDATA[ <p align="left"> <strong>(涓)<br /></strong> <br />One of the basic classes implemented by the Standard Template Library is the vector class. A vector is, essentially, a resizeable array; the vector class allows random access via the [] operator, but adding an element anywhere but to the end of a vector causes some overhead as all of the elements are shuffled around to fit them correctly into memory. Fortunately, the memory requirements are equivalent to those of a normal array. The header file for the STL vector library is vector. (Note that when using C++, header files drop the .h; for C header files - e.g. stdlib.h - you should still include the .h.) Moreover, the vector class is part of the std <a ><font color="#c30000">namespace</font></a>, so you must either prefix all references to the vector template with std:: or include "using namespace std;" at the top of your program.</p> <p>Vectors are more powerful than arrays because the number of functions that are available for accessing and modifying vectors. Unfortunately, the [] operator still does not provide bounds checking. There is an alternative way of accessing the vector, using the function at, which does provide bounds checking at an additional cost. Let's take a look at several functions provided by the vector class:<br /><br /></p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">1</span>聽<span style="COLOR: #000000">unsigned聽</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">聽size();聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Returns聽the聽number聽of聽elements聽in聽a聽vector</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">2</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">push_back(type聽element);聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Adds聽an聽element聽to聽the聽end聽of聽a聽vector</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">3</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">bool</span><span style="COLOR: #000000">聽empty();聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Returns聽true聽if聽the聽vector聽is聽empty</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">4</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">聽clear();聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">聽Erases聽all聽elements聽of聽the聽vector</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">5</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">type聽at(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">聽n);聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Returns聽the聽element聽at聽index聽n,聽with聽bounds聽checking</span></div> <p>also, there are several basic operators defined for the vector class:</p> <pre class="example">= Assignment replaces a vector's contents with the contents of another == An element by element comparison of two vectors [] Random access to an element of a vector (usage is similar to that of the operator with arrays.) Keep in mind that it does not provide bounds checking.</pre> <p>Let's take a look at an example program using the vector class:</p> <pre class="example"> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">聽1</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽2</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽3</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000">聽</span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000">聽std;<br /></span><span style="COLOR: #008080">聽4</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽5</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">聽main()<br /></span><span style="COLOR: #008080">聽6</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">聽7</span>聽<span style="COLOR: #000000">聽聽聽聽vector聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">聽example;聽聽聽聽聽聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Vector聽to聽store聽integers</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽8</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽example.push_back(</span><span style="COLOR: #000000">3</span><span style="COLOR: #000000">);聽聽聽聽聽聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Add聽3聽 onto聽the聽vector</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽9</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽example.push_back(</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);聽聽聽聽聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Add聽10聽to聽the聽end</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">10</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽example.push_back(</span><span style="COLOR: #000000">33</span><span style="COLOR: #000000">);聽聽聽聽聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Add聽33聽to聽the聽end<br /></span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">11</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">聽x</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;聽x</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">example.size();聽x</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)聽<br /></span><span style="COLOR: #008080">12</span>聽<span style="COLOR: #000000">聽聽聽聽{<br /></span><span style="COLOR: #008080">13</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">example[x]</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Should聽output:聽3聽10聽33</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">14</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽}<br /><br /></span><span style="COLOR: #008080">15</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">example.empty())聽聽聽聽聽聽聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Checks聽if聽empty</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">16</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽聽聽聽聽example.clear();聽聽聽聽聽聽聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Clears聽vector</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">17</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽vector聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">聽another_vector;聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Creates聽another聽vector聽to聽store聽integers</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">18</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽another_vector.push_back(</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Adds聽to聽end聽of聽vector</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">19</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽example.push_back(</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">);聽聽聽聽聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Same</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">20</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(example</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">another_vector)聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">To聽show聽testing聽equality</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">21</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽{<br /></span><span style="COLOR: #008080">22</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽example.push_back(</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">);聽<br /></span><span style="COLOR: #008080">23</span>聽<span style="COLOR: #000000">聽聽聽聽}<br /></span><span style="COLOR: #008080">24</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">聽y</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;聽y</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">example.size();聽y</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">25</span>聽<span style="COLOR: #000000">聽聽聽聽{<br /></span><span style="COLOR: #008080">26</span>聽<span style="COLOR: #000000">聽聽聽聽聽聽聽聽cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">example[y]</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Should聽output聽10聽20</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">27</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽}<br /></span><span style="COLOR: #008080">28</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">29</span>聽<span style="COLOR: #000000">}</span></div> </pre> <b>Summary of Vector Benefits</b> <p>Vectors are somewhat easier to use than regular arrays. At the very least, they get around having to be resized constantly using new and delete. Furthermore, their immense flexibility - support for any datatype and support for automatic resizing when adding elements - and the other helpful included functions give them clear advantages to arrays.</p> <p align="left">Another argument for using vectors are that they help avoid memory leaks--you don't have to remember to free vectors, or worry about how to handle freeing a vector in the case of an exception. This simplifies program flow and helps you write tighter code. Finally, if you use the at() function to access the vector, you get bounds checking at the cost of a slight performance penalty.<br /><br /><strong>(浜?</strong><br /><br />聽C++ <a class="kLink" oncontextmenu="return false;" id="KonaLink0" onmouseover="adlinkMouseOver(event,this,0);" style="POSITION: relative; TEXT-DECORATION: underline! important" onclick="adlinkMouseClick(event,this,0);" onmouseout="adlinkMouseOut(event,this,0);" target="_top"><font style="FONT-WEIGHT: 400; COLOR: blue; FONT-FAMILY: Arial, Helvetica, sans-serif; POSITION: relative" color="blue" size="2"><span id="nfzdntt" class="kLink" style="FONT-WEIGHT: 400; COLOR: blue; FONT-FAMILY: Arial, Helvetica, sans-serif; POSITION: relative">vector</span></font></a> is a container template available with Standard Template Library pack. This C++ vector can be used to store similar typed objects sequentially, which can be accessed at a later point of time. As this is a template, all types of data including user defined data types like struct and class can be stored in this container. </p> <p>This article explains briefly about how to insert, delete, access the data with respect to the C++ vector. The type stl::string is used for the purposes of explaining the sample code. Using stl::string is only for sample purposes. Any other type can be used with the C++ vector. <br /><br />The values can be added to the c++ vector at the end of the sequence. The function push_back should be used for this purpose. The <vector> header file should be included in all the header files in order to access the C++ vector and its functions.<br /></p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">聽1</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">vector</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽2</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽3</span>聽<span style="COLOR: #000000">#include聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">iostream.h</span><span style="COLOR: #000000">></span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽4</span>聽<span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">聽5</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">聽main()<br /></span><span style="COLOR: #008080">聽6</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">聽7</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Declaration聽for聽the聽string聽data</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">聽8</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽std::</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">聽strData聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">One</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">聽9</span>聽<span style="COLOR: #000000">聽聽聽聽</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">Declaration聽for聽C++聽vector</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #008080">10</span>聽<span style="COLOR: #008000"></span><span style="COLOR: #000000">聽聽聽聽std::聽vector聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">std::</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">聽str_Vector;<br /></span><span style="COLOR: #008080">11</span>聽<span style="COLOR: #000000">聽聽聽聽str_Vector.push_back(strData);<br /></span><span style="COLOR: #008080">12</span>聽<span style="COLOR: #000000">聽聽聽聽strData聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Two</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">13</span>聽<span style="COLOR: #000000">聽聽聽聽str_Vector.push_back(strData);<br /></span><span style="COLOR: #008080">14</span>聽<span style="COLOR: #000000">聽聽聽聽strData聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Three</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">15</span>聽<span style="COLOR: #000000">聽聽聽聽str_Vector.push_back(strData);<br /></span><span style="COLOR: #008080">16</span>聽<span style="COLOR: #000000">聽聽聽聽strData聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Four</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">;<br /></span><span style="COLOR: #008080">17</span>聽<span style="COLOR: #000000">聽聽聽聽str_Vector.push_back(strData);<br /></span><span style="COLOR: #008080">18</span>聽<span style="COLOR: #000000">}</span></div> <p align="left">The above code adds 4 strings of std::string type to the str_Vector. This uses std:: vector.push_back function. This function takes 1 parameter of the designated type and adds it to the end of the c++ vector.</p> <h2>Accessing Elements of C++ Vector:</h2> <p>聽聽 The elements after being added can be accessed in two ways. One way is our legacy way of accessing the data with vector.at(position_in_integer) function. The position of the data element is passed as the single parameter to access the data.</p> <h3>Using our normal logic for accessing elements stored in C++ Vector:</h3> <p>If we want to access all the data, we can use a for loop and display them as follows.<br /><br /></p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">1</span>聽<span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">聽i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;i聽</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">聽str_Vector.size();聽i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">2</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">3</span>聽<span style="COLOR: #000000">聽聽聽聽std::</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">聽strd聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽str_Vector.at(i);<br /></span><span style="COLOR: #008080">4</span>聽<span style="COLOR: #000000">聽聽聽聽cout</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">strd.c_str()</span><span style="COLOR: #000000"><<</span><span style="COLOR: #000000">endl;<br /></span><span style="COLOR: #008080">5</span>聽<span style="COLOR: #000000">}</span></div> <p>The std:: vector .size() function returns the number of elements stored in the vector.</p> <h3>Using C++ vector iterator provided by STL:</h3> <p>The next way is to use the iterator object provided by the STL. These iterators are general purpose pointers allowing c++ programmers to forget the intricacies of object types and access the data of any type.<br /><br /></p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">1</span>聽<span style="COLOR: #000000">std::vector</span><span style="COLOR: #000000"><</span><span style="COLOR: #000000">std::</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">></span><span style="COLOR: #000000">::iterator聽itVectorData;<br /></span><span style="COLOR: #008080">2</span>聽<span style="COLOR: #000000"></span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(itVectorData聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽str_Vector.begin();聽聽itVectorData聽</span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">聽str_Vector.end();聽itVectorData</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br /></span><span style="COLOR: #008080">3</span>聽<span style="COLOR: #000000">{<br /></span><span style="COLOR: #008080">4</span>聽<span style="COLOR: #000000">聽聽聽聽std::</span><span style="COLOR: #0000ff">string</span><span style="COLOR: #000000">聽strD聽</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">聽</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">(itVectorData);<br /></span><span style="COLOR: #008080">5</span>聽<span style="COLOR: #000000">}</span></div> <h2>Removing elements from C++ vector:</h2> <p>Removing elements one by one from specified positions in c++ vector is achieved with the erase function. </p> <p>The following code demonstrates how to use the erase function to remove an element from position 2 in the str_Vector from our sample.</p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">1</span> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #000000">str_Vector.erase(str_Vector.begin()</span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000">1</span> <span style="COLOR: #000000">,str_Vector.begin()</span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000">2</span> <span style="COLOR: #000000">);</span> </div> <p>聽The following sample demonstrates how to use the erase() function for removing elements 2,3 in the str_Vector used in the above sample.聽</p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"> <span style="COLOR: #008080">1</span> <img src="http://www.shnenglu.com/images/OutliningIndicators/None.gif" align="top" /> <span style="COLOR: #000000">str_Vector.erase(str_Vector.begin()</span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000">1</span> <span style="COLOR: #000000">,str_Vector.begin()</span> <span style="COLOR: #000000">+</span> <span style="COLOR: #000000">3</span> <span style="COLOR: #000000">);</span> </div> <p>If one wants to remove all the elements at once from the c++ vector, the vector.clear() function can be used.</p> <!-- End of text --> <img src ="http://www.shnenglu.com/keyws/aggbug/11193.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/keyws/" target="_blank">keyws</a> 2006-08-13 19:36 <a href="http://www.shnenglu.com/keyws/archive/2006/08/13/11193.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>銆愯漿銆慽teratorshttp://www.shnenglu.com/keyws/archive/2006/08/13/11187.htmlkeywskeywsSun, 13 Aug 2006 11:04:00 GMThttp://www.shnenglu.com/keyws/archive/2006/08/13/11187.htmlhttp://www.shnenglu.com/keyws/comments/11187.htmlhttp://www.shnenglu.com/keyws/archive/2006/08/13/11187.html#Feedback0http://www.shnenglu.com/keyws/comments/commentRss/11187.htmlhttp://www.shnenglu.com/keyws/services/trackbacks/11187.html http://www.cprogramming.com/tutorial/stl/iterators.html The concept of an iterator is fundamental to understanding the C++ Standard Template Library (STL) because iterators provide a means for accessing data stored in container classes such a vector, map, list, etc.

You can think of an iterator as pointing to an item that is part of a larger container of items. For intance, all containers support a function called begin, which will return an iterator pointing to the beginning of the container (the first element) and function, end, that returns an iterator corresponding to having reached the end of the container. In fact, you can access the element by "dereferencing" the iterator with a *, just as you would dereference a pointer.

To request an iterator appropriate for a particular STL templated class, you use the syntax

1std::class_name<template_parameters>::iterator聽name

where name is the name of the iterator variable you wish to create and the class_name is the name of the STL container you are using, and the template_paramters are the parameters to the template used to declare objects that will work with this iterator. Note that because the STL classes are part of the std namespace, you will need to either prefix every container class type with "std::", as in the example, or include "using namespace std;" at the top of your program.

For instance, if you had an STL vector storing integers, you could create an iterator for it as follows:
1std::vector<int>聽myIntVector;
2std::vector<int>::iterator聽myIntVectorIterator;
Different operations and containers support different types of iterator behavior. In fact, there are several different classes of iterators, each with slightly different properties. First, iterators are distinguished by whether you can use them for reading or writing data in the container. Some types of iterators allow for both reading and writing behavior, though not necessarily at the same time.

Some of the most important are the forward, backward and the bidirectional iterators. Both of these iterators can be used as either input or output iterators, meaning you can use them for either writing or reading. The forward iterator only allows movement one way -- from the front of the container to the back. To move from one element to the next, the increment operator, ++, can be used.

For instance, if you want to access the elements of an STL vector, it's best to use an iterator instead of the traditional C-style code. The strategy is fairly straightforward: call the container's begin function to get an iterator, use ++ to step through the objects in the container, access each object with the * operator ("*iterator") similar to the way you would access an object by dereferencing a pointer, and stop iterating when the iterator equals the container's end iterator. You can compare iterators using != to check for inequality, == to check for equality. (This only works for one twhen the iterators are operating on the same container!)

The old approach (avoid)
聽1usingnamespace聽std;
聽2
聽3vector<int>聽myIntVector;
聽4
聽5//聽Add聽some聽elements聽to聽myIntVector
聽6myIntVector.push_back(1);
聽7myIntVector.push_back(4);
聽8myIntVector.push_back(8);
聽9
10for(int聽y=0;聽y<myIntVector.size();聽y++)
11{
12聽聽聽聽cout<<myIntVector[y]<<"";聽聽//Should聽output聽1聽4聽8
13}
The STL approach (use this)
聽1usingnamespace聽std;
聽2
聽3vector<int>聽myIntVector;
聽4vector<int>::iterator聽myIntVectorIterator;
聽5
聽6//聽Add聽some聽elements聽to聽myIntVector
聽7myIntVector.push_back(1);
聽8myIntVector.push_back(4);
聽9myIntVector.push_back(8);
10
11for(myIntVectorIterator聽=聽myIntVector.begin();聽
12聽聽聽聽聽聽聽聽myIntVectorIterator聽!=聽myIntVector.end();
13聽聽聽聽聽聽聽聽myIntVectorIterator++)
14{
15聽聽聽聽cout<<*myIntVectorIterator<<"";聽聽聽聽//Should聽output聽1聽4聽8
16}
17
As you might imagine, you can use the decrement operator, --, when working with a bidirectional iterator or a backward operator.

Iterators are often handy for specifying a particular range of things to operate on. For instance, the range item.begin(), item.end() is the entire container, but smaller slices can be used. This is particularly easy with one other, extremely general class of iterator, the random access iterator, which is functionally equivalent to a pointer in C or C++ in the sense that you can not only increment or decrement but also move an arbitrary distance in constant time (for instance, jump multiple elements down a vector).

For instance, the iterators associated with vectors are random access iterators so you could use arithmetic of the form
iterator + n
where n is an integer. The result will be the element corresponding to the nth item after the item pointed to be the current iterator. This can be a problem if you happen to exceed the bounds of your iterator by stepping forward (or backward) by too many elements.

The following code demonstrates both the use of random access iterators and exceeding the bounds of the array (don't run it!):
1vector<int>聽myIntVector;
2vector<int>::iterator聽myIntVectorIterator;
3myIntVectorIterator聽=聽myIntVector.begin()聽+2;
You can also use the standard arithmetic shortcuts for addition and subtraction, += and -=, with random access iterators. Moreover, with random access iterators you can use <, >, <=, and >= to compare iterator positions within the container.

Iterators are also useful for some functions that belong to container classes that require operating on a range of values. A simple but useful example is the erase function. The vector template supports this function, which takes a range as specified by two iterators -- every element in the range is erased. For instance, to erase an entire vector:
1vector<int>::iterator聽myIntVectorIterator;
2myIntVector.erase(myIntVectorIterator.begin(),聽myIntVectorIterator.end());
which would delete all elements in the vector. If you only wanted to delete the first two elements, you could use
1myIntVector.erase(myIntVectorIterator.begin(),聽myIntVectorIterator.begin()+2);
Note that various container class support different types of iterators -- the vector class, which has served as our model for iterators, supports a random access iterator, the most general kind. Another container, the list container (to be discussed later), only supports bidirectional iterators.

So why use iterators? First, they're a flexible way to access the data in containers that don't have obvious means of accessing all of the data (for instance, maps [to be discussed later]). They're also quite flexible -- if you change the underlying container, it's easy to change the associated iterator so long as you only use features associated with the iterator supported by both classes. Finally, the STL algorithms defined in <algorithm> (to be discussed later) use iterators.

Summary

The Good
  • The STL provides iterators as a convenient abstraction for accessing many different types of containers.
  • Iterators for templated classes are generated inside the class scope with the syntax
    class_name<parameters>::iterator
    
  • Iterators can be thought of as limited pointers (or, in the case of random access iterators, as nearly equivalent to pointers)
The Gotchas
  • Iterators do not provide bounds checking; it is possible to overstep the bounds of a container, resulting in segmentation faults
  • Different containers support different iterators, so it is not always possible to change the underlying container type without making changes to your code
  • Iterators can be invalidated if the underlying container (the container being iterated over) is changed significantly


keyws 2006-08-13 19:04 鍙戣〃璇勮
]]>
銆愬師銆戜竴涓叧浜庡嚱鏁版ā鐗堢紪璇戦敊璇殑璋冭瘯璁板綍http://www.shnenglu.com/keyws/archive/2006/08/12/11154.htmlkeywskeywsSat, 12 Aug 2006 12:32:00 GMThttp://www.shnenglu.com/keyws/archive/2006/08/12/11154.htmlhttp://www.shnenglu.com/keyws/comments/11154.htmlhttp://www.shnenglu.com/keyws/archive/2006/08/12/11154.html#Feedback1http://www.shnenglu.com/keyws/comments/commentRss/11154.htmlhttp://www.shnenglu.com/keyws/services/trackbacks/11154.html 聽聽聽聽聽聽 鍒濆鍑芥暟妯$増錛屼竴涓?/span> bug鈥?/span> 璁╀亢閮侀椃浜嗕竴鐣紝鎯充簡涓涓皬鏃墮兘娌℃湁鎯沖嚭鎵浠ョ劧銆傝櫧姹傚姪浜庣綉緇滐紝鍙戣創浜?/span> vckbase 銆?/span>

聽聽聽聽聽聽 闂宸茬粡瑙e喅錛屽笘瀛愭憳瑕佸涓嬶細

涓?span lang="EN-US">聽聽聽聽聽聽棰?span lang="EN-US">: 鍑芥暟妯$増闂錛屼負浠涔堜笉鑳介噰鐢ㄥ鏂囦歡鏂瑰紡銆?span lang="EN-US">聽
浣?span lang="EN-US">聽聽聽聽聽聽鑰?span lang="EN-US">: 閮櫒 ( 涔︾)
鎵灞炶鍧?span lang="EN-US">: C++ 璁哄潧
鏈笘鍒嗘暟: 0
鍥炲嬈℃暟: 4
鍙戣〃鏃墮棿: 2006-8-12 19:09:50
姝f枃鍐呭:
1
錛?span lang="EN-US">
#include <fstream>
#include <iostream>
using namespace std;
template<class Type >
Type min(Type a, Type b)
{
聽聽聽聽return a < b ? a : b;
}

int main(int argc, char* argv[])
{
聽聽聽聽cout << min(10, 20) << endl;
聽聽聽聽return 0;
}

鍙互緙栬瘧鎴愬姛錛岃繍琛屽緱鍒版紜粨鏋溿?span lang="EN-US">

2錛夊鏂囦歡鏂瑰紡

///////////////////////main.cxx
#include "min.h"
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
聽聽聽聽cout << min(10, 20) << endl;
聽聽聽聽return 0;
}
///////////////////////min.h
#ifndef _MIN_GHH_
#define _MIN_GHH_聽聽1

template<class Type >
Type min(Type a, Type b);

#endif

//////////////////////min.cxx
#include "min.h"

template<class Type >
Type min(Type a, Type b)
{
聽聽聽聽return a < b ? a : b;
}

緙栬瘧鎶ュ憡閿欒錛?span lang="EN-US">
Linking...
20060812_function_template.obj : error LNK2001: unresolved external symbol "int __cdecl min(int,int)" (?min@@YAHHH@Z)
Debug/20060812_function_template.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

20060812_function_template.exe - 2 error(s), 0 warning(s)

////////////////////////////////////
闂錛氫負浠涔堜細鍑虹幇榪欑闂錛屽浣曡В鍐籌紵鐩艱祼鏁欍?span lang="EN-US">
鏈鏂頒慨鏀?span lang="EN-US">:2006-8-12 19:41:10

鍥炲浜?span lang="EN-US">: newgun ( 涔︾)聽

2006-8-12 19:34:29 ( 寰楀垎: 10 )聽

Re: 鍑芥暟妯$増闂錛屼負浠涔堜笉鑳介噰鐢ㄥ鏂囦歡鏂瑰紡銆?span lang="EN-US">
鍦?span lang="EN-US">c++鏍囧噯涓瀹氬彲浠ラ噰鐢ㄥ垎紱葷殑緙栬瘧妯″紡錛屽彧闇瑕侀氳繃鍦ㄦā鏉垮畾涔変腑鐨勫叧閿瓧template 涔嬪墠鍔犱笂鍏抽敭瀛?span lang="EN-US">export 鏉ュ0鏄庝竴涓彲瀵煎嚭鐨勫嚱鏁版ā鏉垮綋鍑芥暟妯℃澘錛岃瀵煎嚭鏃舵垜浠氨鍙互鍦ㄤ換鎰忕▼搴忔枃鏈枃浠朵腑浣跨敤妯℃澘鐨勫疄渚嬪錛?span lang="EN-US">
聽聽// model2.h
// 鍒嗙妯″紡: 鍙彁渚涙ā鏉垮0鏄?span lang="EN-US">
template <typename Type> Type min( Type t1, Type t2 );
// model2.C
// the template definition
export template <typename Type>聽聽聽聽//export鍏抽敭瀛?span lang="EN-US">
Type min( Type t1, Type t2 ) { /* ...*/ }

聽聽聽聽浣嗘槸濂藉儚鐜板湪鐨勫ソ澶氱紪璇戝櫒濡?span lang="EN-US">vc7閮借繕涓嶆敮鎸佽繖縐嶇粨鏋勶紝鎵浠ユ渶濂芥妸妯℃澘鐨勫0鏄?/font>
鍜屽畾涔夐兘鏀懼湪澶存枃浠墮噷銆?span lang="EN-US">

聽聽聽聽聽

聽聽聽聽聽聽 鎰熷彈錛氬緱鍒扮綉鍙嬫彁紺猴紝鐪熸湁涓縐嶁滄煶鏆楄姳鏄庡張涓鏉戔濅箣鎰燂紝榪欎釜鎵璋?/span> bug 鏄繖涔堢畝鍗曞張鏄繖涔堜笉綆鍗曪紒

聽聽聽聽聽聽 涓鐩磋涓哄簲璇ユ槸鑷繁鐨勯敊璇紝浣嗘病鎯沖埌鏄紪璇戝櫒鍜屾爣鍑嗗吋瀹規х殑闂銆傜湅鏉ヨ嚜宸辯殑鎬濈淮涔犳儻搴旇鏈夋墍鏀瑰彉浜嗐傚簲璇ュ瑙掑害鍒嗘瀽闂錛岃屼笉鑳戒竴鍛崇殑鎯沖綋鐒躲?/span>

聽聽聽聽聽聽 Ps 錛氳嚜宸變篃搴旇鑰冭檻灝濊瘯涓涓柊鐨?/span> C++ 緙栬瘧鍣ㄤ簡錛岃佺敤 vc 錛屾劅瑙夊鐨勬爣鍑?/span> C++ 閮戒笉綰紝灝辮薄榪欐浜嬩歡涓鏍楓?/span>



keyws 2006-08-12 20:32 鍙戣〃璇勮
]]>
銆愬師銆戝線浜嬩笉鍙皬錛屾潵鑰呯姽鍙拷錛?/title><link>http://www.shnenglu.com/keyws/archive/2006/08/11/11143.html</link><dc:creator>keyws</dc:creator><author>keyws</author><pubDate>Fri, 11 Aug 2006 14:28:00 GMT</pubDate><guid>http://www.shnenglu.com/keyws/archive/2006/08/11/11143.html</guid><wfw:comment>http://www.shnenglu.com/keyws/comments/11143.html</wfw:comment><comments>http://www.shnenglu.com/keyws/archive/2006/08/11/11143.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/keyws/comments/commentRss/11143.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/keyws/services/trackbacks/11143.html</trackback:ping><description><![CDATA[ <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">灞堟寚涓鏁幫紝涓ゅ勾灝忕錛屽凡榪囩畻鍗娿傚洖蹇嗙爺涓錛屽睍鏈涚爺浜岋紝蹇冧腑棰囧鎰熸叏錛屽枩蹇у洓涓冨紑銆?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鍠滐紝鐩告瘮鍏ュ涔嬪垵錛岀煡璇嗗眰铏芥棤鑴辮儙鎹㈤涔嬫劅錛屼絾涔熷皬鏈夋墍瀛︼紝姣斿凡姣斾漢錛岃繘姝ヤ笉灝戯紒</span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">蹇э紝涓ゅ勾灝忕錛屾椂闂寸揣鍑戯紝浜庡鏈爺絀墮毦鏈夊ぇ鎴愶紱鍐嶇幇瀹炰竴鐐癸紝铏藉閫氫俊錛屼絾鎵句竴婊℃剰宸ヤ綔錛屼粛鍘嬪姏涓嶈交錛屼換閲嶉亾榪滐紒</span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">璇葷爺涓嶄技鏈錛屾垚鐔熷浜嗭紝涔熷紑濮嬭冭檻鐜板疄錛屼笉鏁㈣櫄嫻害鏃ワ紝浣嗙湡鍔姏濂嬫枟璧鋒潵錛屼粛鏈夎糠鑼笉鐭ユ墍涓轟箣鎯戙?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">涓嶈繃錛岃繕濂斤紝榪樻湁涓棰楄櫧絎ㄦ嫏浣嗚繕鍠勪簬鍙嶆濈殑鑴戣錛岃櫧寮礬涓嶅皯錛屼絾涔熺畻涓姝ユ鐨勫悜鍓嶈浜嗐?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">涓ゅ勾錛岀湡鐨勫お鐭紒浣曞喌宸叉氮璐逛竴騫村厜闃村搲</span> <span lang="EN-US">?!</span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">鏃犺涓轟簡宸ヤ綔錛屼負浜嗘瘯涓氾紝榪樻槸涓轟簡鑷繁鍋氱偣鎴愭灉鏉ワ紝閮芥槸璇ュ姫鍔涚殑鏃跺欎簡錛?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">涓嶈皥浜虹敓鎰忎箟絳夌瓑澶ч亾鐞嗭紝灝辨槸涓轟簡榪芥眰涓縐嶇敓瀛樼殑鍩虹錛屽湪涓鍙剼宸茬粡韙忓叆紺句細鐨勬椂鍊欙紝涔熻鏄庣櫧鑷繁搴旇鍋氫簺浠涔堜簡錛?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span> </span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">綆$悊鑷繁錛屽仛璇ュ仛鐨勪簨錛屽仛涓涓Н鏋佺殑鑷繁錛佸畬鍠勮嚜鎴戯紒鍔姏錛?img height="20" src="http://www.shnenglu.com/Emoticons/QQ/45.gif" width="20" border="0" /></span>聽</p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?> <o:p>聽</o:p> </span> <span lang="EN-US"> <o:p>聽</o:p> </span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"> <span lang="EN-US"> <span style="mso-tab-count: 1">聽聽聽聽聽聽 </span>Ps</span> <span style="FONT-FAMILY: 瀹嬩綋; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">錛氳皚浠ユ鏂囷紝鍋氬紑鍗氱邯蹇碉紝涔熶負鎴戞剰涔変笂鐨勭爺浜屽紑濮嬬殑綰康銆?/span> </p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt">聽</p> <img src ="http://www.shnenglu.com/keyws/aggbug/11143.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/keyws/" target="_blank">keyws</a> 2006-08-11 22:28 <a href="http://www.shnenglu.com/keyws/archive/2006/08/11/11143.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.fjzgh.cn" target="_blank">丰满少妇高潮惨叫久久久</a>| <a href="http://www.bamboomart.cn" target="_blank">日韩亚洲国产综合久久久</a>| <a href="http://www.bolson.cn" target="_blank">久久婷婷国产剧情内射白浆</a>| <a href="http://www.laowang66.com.cn" target="_blank">久久久不卡国产精品一区二区 </a>| <a href="http://www.theys.cn" target="_blank">久久精品国产免费观看三人同眠</a>| <a href="http://www.zhe38.cn" target="_blank">久久se精品一区精品二区国产</a>| <a href="http://www.caikuaipeixun.com.cn" target="_blank">国产亚洲色婷婷久久99精品91</a>| <a href="http://www.donglianggc.cn" target="_blank">精品久久久久久无码中文野结衣</a>| <a href="http://www.shenpenghw.cn" target="_blank">久久久精品视频免费观看</a>| <a href="http://www.shufa520.cn" target="_blank">久久婷婷五月综合国产尤物app</a>| <a href="http://www.moisky.com.cn" target="_blank">狠狠色丁香久久婷婷综合五月</a>| <a href="http://www.kaczw3.cn" target="_blank">日本免费久久久久久久网站</a>| <a href="http://www.abloom.com.cn" target="_blank">久久97久久97精品免视看</a>| <a href="http://www.asox.cn" target="_blank">亚洲精品乱码久久久久久不卡</a>| <a href="http://www.2046film.cn" target="_blank">综合网日日天干夜夜久久 </a>| <a href="http://www.noahmachine.com.cn" target="_blank">99国产欧美久久久精品蜜芽</a>| <a href="http://www.gdfw.org.cn" target="_blank">99久久国产主播综合精品</a>| <a href="http://www.rubiconworld.com.cn" target="_blank">久久伊人精品一区二区三区</a>| <a href="http://www.pgfg.net.cn" target="_blank">久久午夜无码鲁丝片</a>| <a href="http://www.mfuq.cn" target="_blank">伊人久久精品影院</a>| <a href="http://www.liuzirui597.cn" target="_blank">久久无码av三级</a>| <a href="http://www.addlife.cn" target="_blank">久久国产欧美日韩精品免费</a>| <a href="http://www.tbssyc.cn" target="_blank">丁香五月网久久综合</a>| <a href="http://www.coubu.cn" target="_blank">麻豆精品久久久久久久99蜜桃 </a>| <a href="http://www.ysaoyx.cn" target="_blank">亚洲精品乱码久久久久久蜜桃不卡</a>| <a href="http://www.tphv.cn" target="_blank">94久久国产乱子伦精品免费 </a>| <a href="http://www.1yaofang.cn" target="_blank">久久久一本精品99久久精品88</a>| <a href="http://www.lwtjf.cn" target="_blank">狠狠久久综合伊人不卡</a>| <a href="http://www.usgold.cn" target="_blank">99久久久精品免费观看国产</a>| <a href="http://www.todouba.cn" target="_blank">久久精品aⅴ无码中文字字幕不卡 久久精品成人欧美大片 </a>| <a href="http://www.77gly.cn" target="_blank">久久只有这里有精品4</a>| <a href="http://www.osgh.cn" target="_blank">伊人久久综合热线大杳蕉下载</a>| <a href="http://www.sic-mosi2.cn" target="_blank">国产69精品久久久久观看软件</a>| <a href="http://www.zgyjys.cn" target="_blank">久久久91人妻无码精品蜜桃HD</a>| <a href="http://www.benzclub.com.cn" target="_blank">久久青草国产手机看片福利盒子</a>| <a href="http://www.yzx777.cn" target="_blank">久久久久国产精品熟女影院</a>| <a href="http://www.jhyjpj.cn" target="_blank">国产精品久久久久蜜芽</a>| <a href="http://www.4fro.cn" target="_blank">久久精品亚洲AV久久久无码</a>| <a href="http://www.517down.cn" target="_blank">区久久AAA片69亚洲</a>| <a href="http://www.pvhb.cn" target="_blank">久久久久亚洲AV成人网人人网站 </a>| <a href="http://www.job158.cn" target="_blank">久久国内免费视频</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>