• <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 的數(shù)據(jù)的存入和輸出:

            #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 );//把元素一個(gè)一個(gè)存入到vector中

               }

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

               {

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

               }

               cont << endl;

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

            vector<int>::iterator iter;

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

            {
                cout << *iter << endl;
            }

            2. 對(duì)于二維vector的定義。

            1)定義一個(gè)10個(gè)vector元素,并對(duì)每個(gè)vector符值1-10。

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

            using namespace std;

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

            //定義一個(gè)二維的動(dòng)態(tài)數(shù)組,有10行,每一行是一個(gè)用一個(gè)vector存儲(chǔ)這一行的數(shù)據(jù)。

            所以每一行的長度是可以變化的。之所以用到vector<int>(0)是對(duì)vector初始化,否則不能對(duì)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)定義一個(gè)行列都是變化的數(shù)組。

            #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 );//要對(duì)每一個(gè)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類的成員函數(shù)~

            push_back()插入一個(gè)元素
            pop_back() 可以彈出最后ch一個(gè)元素
            erase(iterator   it)可以刪除指定位置的元素
            size()求vector中的已存的元素個(gè)數(shù)
            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 閱讀(4512) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 學(xué)習(xí)筆記轉(zhuǎn)載
            Priceline Travel
            Priceline Travel
            久久午夜综合久久| 99久久精品免费观看国产| 国产福利电影一区二区三区久久老子无码午夜伦不| 久久久久久曰本AV免费免费| 亚洲精品乱码久久久久久蜜桃不卡 | 国产成人精品久久一区二区三区av | 久久99久国产麻精品66| 亚洲精品乱码久久久久66| 精品国产一区二区三区久久| 精品久久人人做人人爽综合| 欧洲人妻丰满av无码久久不卡 | 99久久精品国内| 97精品伊人久久久大香线蕉 | 天天久久狠狠色综合| 亚洲精品无码久久千人斩| 国产精品久久久久影院色| 日本亚洲色大成网站WWW久久| 久久久无码精品亚洲日韩按摩| 久久久久黑人强伦姧人妻| 久久精品国产精品亚洲精品| 久久www免费人成看国产片| 久久久久人妻一区精品性色av| 精品久久久久久国产牛牛app| 一本色综合网久久| 性做久久久久久免费观看| 国产精品美女久久久m| 丁香狠狠色婷婷久久综合| 噜噜噜色噜噜噜久久| 欧洲国产伦久久久久久久| 精品亚洲综合久久中文字幕| 久久精品国产色蜜蜜麻豆| 大香网伊人久久综合网2020| 久久国产热精品波多野结衣AV| 精品国产99久久久久久麻豆| 久久久亚洲精品蜜桃臀| 久久国产午夜精品一区二区三区| 久久久久夜夜夜精品国产| 日本三级久久网| 国产欧美久久一区二区| 久久国产精品久久久| 精品久久久久久|