• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            yoyouhappy的秘密花園
            歡迎來到我的秘密花園^^
            posts - 16,comments - 33,trackbacks - 0



            1.vector 的數據的存入和輸出:

            #include<stdio.h>
            #include<vector>
            #include <iostream>

            using namespace std;

            void main()

            {

               int i = 0;

                vector<int> v;

                for( i = 0; i < 10; i++ )

               {

                         v.push_back( i );//把元素一個一個存入到vector中

               }

               for( i = 0; i < v.size(); i++ )//v.size() 表示vector存入元素的個數

               {

                      cout << v[ i ] << "  "; //把每個元素顯示出來

               }

               cont << endl;

            注:你也可以用v.begin()和v.end() 來得到vector開始的和結束的元素地址的指針位置。你也可以這樣做:

            vector<int>::iterator iter;

            for( iter = v.begin(); iter != v.end(); iter++ )

            {
                cout << *iter << endl;
            }

            2. 對于二維vector的定義。

            1)定義一個10個vector元素,并對每個vector符值1-10。

            #include<stdio.h>
            #include<vector>
            #include <iostream>

            using namespace std;

            void main()
            {
             int i = 0, j = 0;

            //定義一個二維的動態數組,有10行,每一行是一個用一個vector存儲這一行的數據。

            所以每一行的長度是可以變化的。之所以用到vector<int>(0)是對vector初始化,否則不能對vector存入元素。
             vector< vector<int> > Array( 10, vector<int>(0) ); 

            for( j = 0; j < 10; j++ )
             {
              for ( i = 0; i < 9; i++ )
              {
               Array[ j ].push_back( i );
              }
             }

             for( j = 0; j < 10; j++ )
             {
              for( i = 0; i < Array[ j ].size(); i++ )
              {
               cout << Array[ j ][ i ] << "  ";
              }
              cout<< endl;
             }
            }

            2)定義一個行列都是變化的數組。

            #include<stdio.h>
            #include<vector>
            #include <iostream>

            using namespace std;

            void main()
            {
             int i = 0, j = 0;

             vector< vector<int> > Array;
             vector< int > line;
             for( j = 0; j < 10; j++ )
             {
              Array.push_back( line );//要對每一個vector初始化,否則不能存入元素。
              for ( i = 0; i < 9; i++ )
              {
               Array[ j ].push_back( i );
              }
             }

             for( j = 0; j < 10; j++ )
             {
              for( i = 0; i < Array[ j ].size(); i++ )
              {
               cout << Array[ j ][ i ] << "  ";
              }
              cout<< endl;
             }
            }
                                                                                              -----zz自 http://blog.csdn.net/tjh666/archive/2007/05/11/1604119.aspx


            下面是我找的一些常用vector類的成員函數~

            push_back()插入一個元素
            pop_back() 可以彈出最后ch一個元素
            erase(iterator   it)可以刪除指定位置的元素
            size()求vector中的已存的元素個數
            clear()可以清空vector中的元素
            Vector constructors create vectors and initialize them with some data
            Vector operators compare, assign, and access elements of a vector
            assign assign elements to a vector
            at returns an element at a specific location
            back returns a reference to last element of a vector
            begin returns an iterator to the beginning of the vector
            capacity returns the number of elements that the vector can hold
            clear removes all elements from the vector
            empty true if the vector has no elements
            end returns an iterator just past the last element of a vector
            erase removes elements from a vector
            front returns a reference to the first element of a vector
            insert inserts elements into the vector
            max_size returns the maximum number of elements that the vector can hold
            pop_back removes the last element of a vector
            push_back add an element to the end of the vector
            rbegin returns a reverse_iterator to the end of the vector
            rend returns a reverse_iterator to the beginning of the vector
            reserve sets the minimum capacity of the vector
            resize change the size of the vector
            size returns the number of items in the vector
            swap swap the contents of this vector with another

            posted on 2007-07-18 14:00 yoyouhappy 閱讀(4510) 評論(0)  編輯 收藏 引用 所屬分類: 學習筆記轉載
            Priceline Travel
            Priceline Travel
            久久99亚洲综合精品首页| 欧美性大战久久久久久| 久久er国产精品免费观看2| 国产亚洲美女精品久久久| 亚洲&#228;v永久无码精品天堂久久| 欧美亚洲国产精品久久| 好属妞这里只有精品久久| 亚洲AV伊人久久青青草原| 国产精品一久久香蕉国产线看 | 熟妇人妻久久中文字幕| 欧美精品一区二区精品久久| 超级碰碰碰碰97久久久久| 99久久免费国产精品| 色婷婷综合久久久久中文 | 久久久免费观成人影院| 国产精品99久久99久久久| 色综合合久久天天给综看| 久久精品国产只有精品2020| 人人狠狠综合久久88成人| 色综合久久中文字幕综合网| 999久久久国产精品| 91久久婷婷国产综合精品青草| 久久免费视频1| 亚洲欧美国产精品专区久久| 亚洲国产精品热久久| 91精品国产乱码久久久久久 | 亚洲国产一成久久精品国产成人综合 | 狠狠色噜噜狠狠狠狠狠色综合久久| 中文字幕精品无码久久久久久3D日动漫| 香蕉久久久久久狠狠色| 蜜臀久久99精品久久久久久小说| 午夜福利91久久福利| 国内精品久久久久影院网站| 久久91精品国产91久久户| 久久99精品久久久久久| 欧美日韩精品久久久久| 成人免费网站久久久| 久久久久AV综合网成人| 无码国内精品久久人妻| 婷婷五月深深久久精品| 久久精品国产亚洲AV无码麻豆|