c/c++ 標準庫 vector

來源:互聯網
上載者:User

標籤:str   編譯器   cout   name   ++   size_type   using   while   必須   

c/c++ 標準庫 vector標準庫 vector的小例子 test1~test7
#include <iostream>#include <vector>using namespace std;class A{public:  A(){cout << "AA" << endl;}};int main(){  //test1                                                                         /*                                                                              vector<int> v1;                                                                 vector<vector<string>> v2;                                                      */  //test2                                                                         /*                                                                              vector<A> v3(2);//建立2個元素的vector                                           //因為v4所提供的值不能作為元素的初始值,                                        //所以編譯器嘗試用預設值初始化vector,所以{4}的含義就變成了(4),                 //也就是建立了4個元素的vector                                                   vector<A> v4{4};//建立4個元素的vector                                           vector<int> v5{15};//建立1個元素的vector                                        for(auto a : v5){                                                                 cout << a << endl;                                                            }                                                                               */  //test3                                                                         /*                                                                              vector<int> v1;//size:0                                                         cout << v1.size() << endl;                                                      vector<int> v2(10);//size:10                                                    cout << v2.size() << endl;                                                      vector<int> v3(10, 12);//size:10                                                cout << v3.size() << endl;                                                      vector<int> v4{11};//size:1                                                     cout << v4.size() << endl;                                                      vector<int> v5{10, 12};//size:2                                                 cout << v5.size() << endl;                                                      vector<string> v6{10};//size:10                                                 cout << v6.size() << endl;                                                      vector<string> v7{10, "ab"};//size:10                                           cout << v7.size() << endl;                                                      */  //test4                                                                         /*                                                                              vector<int> v;                                                                  int s;                                                                          while(cin >> s){                                                                  v.push_back(s);                                                               }                                                                               cout << v.size() << endl;                                                       */  //test5                                                                         /*                                                                              vector<string> v;                                                               string s;                                                                       while(cin >> s){                                                                  v.push_back(s);                                                               }                                                                               cout << v.size() << endl;                                                       */  //test6                                                                         /*                                                                              //vector::size_type t;編譯不過,必須帶<int>                                     vector<int>::size_type t;                                                       */  //test7                                                                         /*                                                                              vector<int> v(11, 0);                                                           int grade;                                                                      while(cin >> grade){                                                              if(grade <= 100)                                                                  ++v[grade / 10];                                                            }                                                                               for(auto a : v){                                                                  cout << a << " ";                                                             }                                                                               cout << endl;                                                                   */}

c/c++ 標準庫 vector

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.