??xml version="1.0" encoding="utf-8" standalone="yes"?>国产亚洲精久久久久久无码,久久亚洲私人国产精品vA,99久久这里只有精品http://www.shnenglu.com/keyws/C++ && keyWordSpottingzh-cnTue, 01 Jul 2025 15:14:08 GMTTue, 01 Jul 2025 15:14:08 GMT60【code】一个可以精到毫秒的计时程序代?/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"> cd出导入类别的W号定义</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"> * cdUW   ghhTimer<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"> *    本类Ҏ(gu)准库计时函数q行?jin)封装,可以实现非常_的计Ӟ毫秒U别<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"> *    在所要计时程序段之前Q调用Start函数Q程序段l束Ӟ调用Pause函数Q?br /></span><span style="COLOR: #008080">25</span> <span style="COLOR: #008000"> *    多次调用E序D,卛_以比较精的估计E序D늚q行旉<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"> 当表已经停止或者暂停时启动停表Q成功返回true,否则q回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"> 表运行时暂停计时,成功q回trueQ否则返回false</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"> 得到当前U篏的秒?/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"> 得到当前U篏的毫U数</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>【note】Effective 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’t 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 “prefer 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’t know about constructors and destructors.

11. free 操作不会(x)调用析构函数Q如果指针所指对象本w又分配?jin)内存,则?x)造成内存丢失?/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’s 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 “normal?form of new

Item 10: Write operator delete if you write operator new

让我们回q头ȝ看这样一个基本问题:(x)Z么有必要写自q operator new ?/span> operator delete Q答案通常是:(x)Z(jin)效率。缺省的 operator new ?/span> operator delete h非常好的通用性,它的q种灉|性也使得在某些特定的场合下,可以q一步改善它的性能。尤其在那些需要动态分配大量的但很的对象的应用程序里Q情冉|是如此?/span>

 



keyws 2006-08-22 17:24 发表评论
]]>
【note】《C++ Primer Q?8.4节“动态分配的对象”》学?fn)笔?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   
   动态分配的对象Q程序员完全控制分配与释放,分配在程序的I闲存储区(free store)的可用内存池中?span lang="EN-US">
 
 1
Q单个对象的动态分配与释放Q?span lang="EN-US">
 new表达式没有返回实际分配的对象Q而是q回指向该对象的指针。对该对象的全部操作都要通过q个指针间接完成?span lang="EN-US">
 随机分配的内存具有随机的位模式,初始化,例如Q?span lang="EN-US">

 int* pi = new int(0);


 

I闲存储区是有限的资源,若被耗尽Q?span lang="EN-US">new表达式会(x)p|Q抛?span lang="EN-US">bad_alloc异常?span lang="EN-US">
 q样做没有必?span lang="EN-US">:

     if  ( pi != 0 )
        delete pi;

  说明Q如果指针操作数被设|ؓ(f)0Q则C++保证delete表达式不?x)调用操作?span lang="EN-US">delete()。所以没有必要测试其是否?span lang="EN-US">0?span lang="EN-US">
 ?span lang="EN-US">delete表达式之后,pi被称作空(zhn)指针,x向无效内存的指针。空(zhn)指针是E序错误的根源,对象释放后,该指针讄?span lang="EN-US">0?span lang="EN-US">
 
 2Q?span lang="EN-US">auto_ptr
 auto_ptr?span lang="EN-US">C++标准库提供的cL板,它可以帮助程序员自动理?span lang="EN-US">new表达式动态分配的单个对象Q但是,它没有对数组理提供cM支持。它的头文g为:(x) 

    #include  < memory >  

  ?span lang="EN-US">auto_ptr对象的生命期l束Ӟ动态分配的对象被自动释放?span lang="EN-US">
 auto_ptrcL板背后的主要动机是支持与普通指针类型相同的语法Q但是ؓ(f)auto_ptr对象所指对象的释放提供自动理。例Q?span lang="EN-US">

     //  W一U初始化形式
    std::auto_ptr< int > pi(  new   int (1024) );     // 

 auto_ptr cL板支持所有权概念Q当一?span lang="EN-US">auto_ptr对象被用另一?span lang="EN-US">auto_ptr对象初始化赋值时Q左边被赋值或初始化的对象拥有了(jin)I闲存储区内底层对象的所有权Q而右边的auto_ptr对象?font color="#ff0000">撤消所有责?/font>。例Q?span lang="EN-US">

    std::auto_ptr<std:: string > pstr_auto(  new  std:: string ( "Brontonsaurus" ) );
    
// 
W二U初始化形式
    std::auto_ptr<std:: string > pstr_auto2( pstr_auto );

  判断是否指向一个对象,例:(x)

     //  W三U初始化形式
    auto_ptr < int >  p_auto_int;    
    
if  ( p_auto_int. get ()  ==   0  )
        
    
else
        
//  重置底层指针Q必M用此函数        
        p_auto_int.reset(  new   int 1024  ) );


 3Q数l的动态分配与释放
 
使用C++标准?span lang="EN-US">string,
避免使用C风格字符串数l?span lang="EN-US">
 为避免动态分配数l的内存理带来的问题,一般徏议用标准库vector?span lang="EN-US">list?span lang="EN-US">string容器cd?span lang="EN-US">
 
 4Q常量对象的动态分配与释放
 
可以使用new表达式在I闲存储区内创徏一?span lang="EN-US">const对象Q例Q?span lang="EN-US">

     //  此时必须初始化,否则~译错误
     const   int * pci =  new   const   int (1024);    

  我们不能在空闲存储区创徏内置cd元素?span lang="EN-US">const数组Q原因是Q我们不能初始化?span lang="EN-US">new表达式创建的内置cd数组的元素。例Q?span lang="EN-US">

     const   int * pci =  new   const   int [100];  //  ~译错误


 5
Q定?span lang="EN-US">new表达?span lang="EN-US">
 new表达式的W三UŞ式允许程序员要求对象创建在已经被分配好的内存中。称为:(x)定位new表达式(placement new expression)。程序员?span lang="EN-US">new表达式中指定待创建对象所在的内存地址。如下所C:(x)
 new
Q?span lang="EN-US">place_address) type-specifier
 注意Q?span lang="EN-US">place_address必须是个指针Q必d含头文g<new>。这设施允许程序员预分配大量的内存Q供以后通过q种形式?span lang="EN-US">new表达式创建对象。例如:(x)

    #include  < iostream >
    #include 
< new >      //  必须包含q个头文?/span>
    
    
const   int  chunk  =   16 ;
    
class  Foo
    
{
        
    }
;
    
    
char *  buf  =   new   char sizeof (Foo)  *  chunk ];
    
    
int  main( int  argc,  char *  argv[])
    
{
        
//  只有q种形式的创建,没有配对形式的delete 
        Foo *  pb  =   new  (buf) Foo;
                
        delete[] buff;
        
        
return   0 ;
    }



keyws 2006-08-22 14:54 发表评论
]]>
【note】Effective 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 I(yng)tem 17

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

    strcpy(data, rhs.data);
    
    
return   * this //  see I(yng)tem 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 发表评论
]]>
【{】Operator 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    学习(fn)数据l构Q用C(jin)输入输出q算W重载,l果~译之下Q错误重重,Q随卛_止学?fn)进度,q查源Q在p巨大脑力与时间成本之后,l于知自己错误之所在,定位于名字空间之困扰。ؓ(f)牢记教训Q写一化版本记?/span> debug q程如下Q警C己?br />

问题Q?br />   

   有如下两个代码文Ӟ(x)
   // 20060816_operator.cxx

 1 #include <iostream>
 2 using namespace std;
 3 #include "20060816_operator.h"
 4 int main(int argc, char* argv[])
 5 {
 6     const std::string GHH("GuoHonghua");
 7     Honghua ghh(GHH);
 8     cout << ghh << endl;
 9     return 0;
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>
10 class Honghua
11 {
12     friend std::ostream& operator<<(std::ostream& os, const Honghua& ghh);
13 public:
14     Honghua(const std::string& ghh) : _ghh(ghh)
15     {
16     }
17 
18 private:
19     std::string _ghh;
20 };
21 
22 std::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_

用上面两个文件徏立工E,vc6.0下编译会(x)出错。报告如下:(x)

--------------------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)
解决:
   

1Q?span style="FONT: 7pt 'Times New Roman'">  调整名字I间声明和自定义头文件的ơ序Q如下:(x)

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

2Q?span style="FONT: 7pt 'Times New Roman'">  把类定义于标准名字之内,20060816_operator.h文g修改如下Q不推荐Q?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>
10 namespace 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_ 

3Q?span style="FONT: 7pt 'Times New Roman'">  使用头文?/span>iostream.h代替iostream,比较落后的方式(不推?/span>!Q?br />

 1 // 20060816_operator.cxx
 2 // #include <iostream>
 3 #include <iostream.h>
 4 #include <iostream.h>
 5 #include "20060816_operator.h"
 6 int main(int argc, char* argv[])
 7 {
 8     const std::string GHH("GuoHonghua");
 9     Honghua ghh(GHH);
10     cout << ghh << endl;
11     return 0;
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 
12 class Honghua
13 {
14     friend ostream& operator<<(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 ostream& operator<<(ostream& os, const Honghua& ghh)
26 {
27     os << ghh._ghh;
28     return os;
29 }
30 
31 #endif // end of _20060816_OPERATOR_GHH_

4Q?span style="FONT: 7pt 'Times New Roman'">  M时候都不?/span>using namespace 声明Q这是只需要修?/span>20060816_operator.cxx文g如下Q?br />

 1 #include <iostream>
 2 #include "20060816_operator.h"
 3 int 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     return 0;
11 }

体会(x)Q?br />   名字I间本来是Z(jin)解决名字冲突问题而引入,以标准库不受外界媄(jing)响。在q个意义上来_(d)using namespace std;不是可以随意使用的语句,应该考虑到它的位|对E序的可能媄(jing)响,而最d的杜l错误的解决办法是在M时候Q何情况下都不使用此语句!



keyws 2006-08-16 21:09 发表评论
]]>
【{】vector Q二Q?/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="ieuwiai" class="body-content"> <div id="wmcoccw" class="header-box"> <a >www.cppreference.com</a> <br /> <br />assign </div> <div id="m4miiiq" 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="mugy4i2" class="name-format">back </div> <div id="w2ymcoo" 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="24wkoyi" class="name-format">at </div> <div id="uceuaws" 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="u6iyc44" class="related-name-format"> <hr /> </div> <div id="saos4aa" class="name-format">capacity </div> <div id="ucqi64s" 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="4ukq2kw" class="name-format">begin </div> <div id="c4wm22a" 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="iggymww" class="related-name-format"> <hr /> </div> <div id="gam4ig4" class="name-format">max_size </div> <div id="ewmew46" 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="4qsycaa" class="related-name-format"> <hr /> </div> <div id="ywmo4qq" class="name-format">clear </div> <div id="gwaqgo6" 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="i4skqa2" class="related-name-format"> <hr /> </div> <div id="wyegg4o" class="name-format">empty </div> <div id="mqimgm2" 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="eswm2cq" class="related-name-format"> <hr /> </div> <div id="ommyse6" class="name-format">end </div> <div id="si4m2kw" 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="yume644" class="name-format">erase </div> <div id="imgyokg" 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="y6uqswk" class="related-name-format">Related topics: </div> <div id="qkc4uww" 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="4wawccg" class="name-format">front </div> <div id="aa2meco" 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="ss44ggs" class="related-name-format">Related topics: </div> <div id="mmskoys" 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="eqikws2" class="name-format">insert </div> <div id="aec22gs" 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="44ewmk2" class="related-name-format">Related topics: </div> <div id="oiaaigu" 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="24w2iem" class="name-format">Vector constructors </div> <div id="ui4mc66" 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="kmy6wyg" class="name-format">pop_back </div> <div id="ei4cge4" 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="4sw2w2q" class="related-name-format">Related topics: </div> <div id="g6aqgea" 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="w2mcig4" class="name-format">push_back </div> <div id="2eaqi4a" 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="ikciwqo" class="related-name-format">Related topics: </div> <div id="ck2e4gc" 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="6ymaccu" class="name-format">rbegin </div> <div id="mcym6ge" 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="ckekoo4" class="related-name-format">Related topics: </div> <div id="4esimkg" class="related-content"> <a >begin</a> <br /> <a >end</a> <br /> <a >rend</a> </div> <div> </div> <hr /> <div id="g4g42e2" class="name-format">rend </div> <div id="uiouw2e" 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="ymc6kw4" class="related-name-format">Related topics: </div> <div id="2eimcaa" class="related-content"> <a >begin</a> <br /> <a >end</a> <br /> <a >rbegin</a> </div> <div> </div> <hr /> <div id="mqkogqq" class="name-format">reserve </div> <div id="icgiuo4" 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="gki4use" class="related-name-format">Related topics: </div> <div id="smwau4g" class="related-content"> <a >capacity</a> </div> <div> </div> <hr /> <div id="yia6mes" class="name-format">resize </div> <div id="46oaoqg" 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="ouqgy44" class="related-name-format">Related topics: </div> <div id="4y4oigc" class="related-content"> <a >Vector constructors & destructors</a> <br /> <a >capacity</a> <br /> <a >size</a> </div> <div> </div> <hr /> <div id="igkkmeo" class="name-format">size </div> <div id="ycum2ii" 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="k4qwwig" class="related-name-format">Related topics: </div> <div id="gg4kq8e" 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="mcuqusy" class="name-format">swap </div> <div id="cwyc422" 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="smmsu4k" class="related-name-format">Related topics: </div> <div id="ekacscw" class="related-content">(C++ Lists) <a >splice</a></div> <div> </div> <hr /> <div id="aaqcqg4" class="name-format">Vector operators </div> <div id="48uook2" 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="os2eesq" class="related-name-format">Related topics: </div> <div id="gmsyccw" 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>【{】vectorQ一Q?/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="84eoguu" 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>【{】iteratorshttp://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

1 std::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)
 1 using namespace std;
 2 
 3 vector<int> myIntVector;
 4 
 5 // Add some elements to myIntVector
 6 myIntVector.push_back(1);
 7 myIntVector.push_back(4);
 8 myIntVector.push_back(8);
 9 
10 for(int y=0; y<myIntVector.size(); y++)
11 {
12     cout<<myIntVector[y]<<" ";  //Should output 1 4 8
13 }
The STL approach (use this)
 1 using namespace std;
 2 
 3 vector<int> myIntVector;
 4 vector<int>::iterator myIntVectorIterator;
 5 
 6 // Add some elements to myIntVector
 7 myIntVector.push_back(1);
 8 myIntVector.push_back(4);
 9 myIntVector.push_back(8);
10 
11 for(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!):
1 vector<int> myIntVector;
2 vector<int>::iterator myIntVectorIterator;
3 myIntVectorIterator = 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:
1 vector<int>::iterator myIntVectorIterator;
2 myIntVector.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        初学函数模版Q一个?/span> bug?/span> 让俺郁闷?jin)一番,想了(jin)一个小旉没有惛_所以然。虽求助于网l,发脓(chung)?/span> vckbase ?/span>

       问题已经解决Q帖子摘要如下:(x)

?span lang="EN-US">      ?span lang="EN-US">: 函数模版问题Qؓ(f)什么不能采用多文g方式?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
正文内容:
1
Q?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;
}

可以~译成功Q运行得到正结果?span lang="EN-US">

2Q多文g方式

///////////////////////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;
}

~译报告错误Q?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)

////////////////////////////////////
问题Qؓ(f)什么会(x)出现q种问题Q如何解冻ID教?span lang="EN-US">
最C?span lang="EN-US">:2006-8-12 19:41:10

 

回复?span lang="EN-US">: newgun ( 书童

2006-8-12 19:34:29 ( 得分: 10

Re: 函数模版问题Qؓ(f)什么不能采用多文g方式?span lang="EN-US">
?span lang="EN-US">c++标准中规定可以采用分ȝ~译模式Q只需要通过在模板定义中的关键字template 之前加上关键?span lang="EN-US">export 来声明一个可导出的函数模板当函数模板Q被导出时我们就可以在Q意程序文本文件中使用模板的实例如Q?span lang="EN-US">
  // model2.h
// 分离模式: 只提供模板声?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都还不支持这U结构,所以最好把模板的声?/font>
和定义都攑֜头文仉?span lang="EN-US">

     

       感受Q得到网友提C,真有一U“柳暗花明又一村”之感,q个所?/span> bug 是这么简单又是这么不单!

       一直认为应该是自己的错误,但没惛_是编译器和标准兼Ҏ(gu)的问题。看来自q思维?fn)惯应该有所改变?jin)。应该多角度分析问题Q而不能一味的惛_然?/span>

       Ps Q自׃应该考虑试一个新?/span> C++ ~译器了(jin)Q老用 vc Q感觉学的标?/span> C++ 都不U,pq次事g一栗?/span>



keyws 2006-08-12 20:32 发表评论
]]>
【原】往事不可谏Q来者犹可追Q?/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'">屈指一敎ͼ两年硕Q已q算半。回忆研一Q展望研二,?j)中颇多感慨Q喜忧四七开?/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'">喜,相比入学之初Q知识层虽无p换骨之感Q但也小有所学,比已比hQ进步不!</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'">忧,两年硕Q时间紧凑,于学术研I有大成;再现实一点,虽学通信Q但找一满意工作Q仍压力不轻QQ重道q!</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'">ȝ不似本科Q成熟多?jin),也开始考虑现实Q不敢虚度日,但真努力奋斗hQ仍有迷茫不知所Z惑?/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'">不过Q还好,q有一颗虽W拙但还善于反思的脑袋Q虽弯\不少Q但也算一步步的向前行?jin)?/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'">两年Q真的太短!何况已浪费一q光阴哉</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'">无论Z(jin)工作Qؓ(f)?jin)毕业,q是Z(jin)自己做点成果来,都是该努力的时候了(jin)Q?/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'">不谈人生意义{等大道理,是Z(jin)q求一U生存的基础Q在一只脚已经t入C会(x)的时候,也该明白自己应该做些什么了(jin)Q?/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'">理自己Q做该做的事Q做一个积极的自己Q完善自我!努力Q?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'">Q}以此文,做开博纪念,也ؓ(f)我意义上的研二开始的U念?/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.nba592.cn" target="_blank">þþŷղAV</a>| <a href="http://www.pass3d.cn" target="_blank">ĻƷѾþ5151</a>| <a href="http://www.szjjls.cn" target="_blank">97þþþ</a>| <a href="http://www.amqinhang.cn" target="_blank">޺ݺۺϾþ</a>| <a href="http://www.xiangyuesiji.cn" target="_blank">޹Ʒþþž </a>| <a href="http://www.weryuadfsd.cn" target="_blank">vaþþþ</a>| <a href="http://www.hbjyhg.cn" target="_blank">ƷþþþþĻһ</a>| <a href="http://www.g172.cn" target="_blank">ݺݾþۺ</a>| <a href="http://www.j2142.cn" target="_blank">ղƷ99þþþþ</a>| <a href="http://www.jhgppeizi.com.cn" target="_blank">˾Ʒһþ</a>| <a href="http://www.hefxxw.cn" target="_blank">þþƷAVþþ</a>| <a href="http://www.corporateavenue.cn" target="_blank">Ʒþþþþ</a>| <a href="http://www.mzwsjd.cn" target="_blank">þоƷ</a>| <a href="http://www.enetbase.cn" target="_blank">ɫۺϺϾþۺӿ</a>| <a href="http://www.nba592.cn" target="_blank">99þѹƷػ</a>| <a href="http://www.qingjian8.cn" target="_blank">ƷҹþøƬ</a>| <a href="http://www.45jj.cn" target="_blank">ɫۺϾþ</a>| <a href="http://www.zixunlawyer.com.cn" target="_blank">þþƷh</a>| <a href="http://www.h5982.cn" target="_blank">޹Ʒ˾þ</a>| <a href="http://www.ejtc.cn" target="_blank">þþۺ㽶ۺ</a>| <a href="http://www.qxmobile.cn" target="_blank">˾þþƷһ</a>| <a href="http://www.xqt007.cn" target="_blank">þþþòҰ¸߳</a>| <a href="http://www.z5621.cn" target="_blank">Ӱһþþþó˾Ʒۺ </a>| <a href="http://www.0757vd.cn" target="_blank">þþþһƷ</a>| <a href="http://www.alilinfen.cn" target="_blank">þ66͵Ʒ9</a>| <a href="http://www.info88.cn" target="_blank">Ժձһձþ</a>| <a href="http://www.ebsiask.cn" target="_blank">þþƷAVȫ</a>| <a href="http://www.amqinhang.cn" target="_blank">޹˾ƷŮ˾þþ</a>| <a href="http://www.tvue.cn" target="_blank">þþĻ</a>| <a href="http://www.freejavbt.cn" target="_blank">AVպAVþþ</a>| <a href="http://www.mayray.com.cn" target="_blank">ɫþþۺľþһ</a>| <a href="http://www.2046film.cn" target="_blank">þù鶹91</a>| <a href="http://www.zhoupeng520.cn" target="_blank">޾Ʒһ߾þ</a>| <a href="http://www.hx0451.cn" target="_blank">ۺϳ˾þС˵</a>| <a href="http://www.cext.cn" target="_blank">69Ʒþþþ99 </a>| <a href="http://www.atbook.cn" target="_blank">һɫþۺ޾Ʒ</a>| <a href="http://www.smxsj.cn" target="_blank">þۺɫ</a>| <a href="http://www.ithaiyang.com.cn" target="_blank">99þ˾ƷۺϹۿ</a>| <a href="http://www.dzeuegg.cn" target="_blank">99þ99þþþƷ</a>| <a href="http://www.tyo8.cn" target="_blank">ˬݾþþۺ鶹</a>| <a href="http://www.fygjkd.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>