vector容器01之存放內建型資料型別

2021-10-25 22:28:42 字數 791 閱讀 9916

容器:vector

演算法:for_each

迭代器:vector< int >::iterator

#include

using

namespace std;

//容器可以簡單理解為陣列,迭代器可以簡單理解成指標

//vector容器存放內建資料型別

//包含標頭檔案

#include

#include

//包含標準演算法標頭檔案

void

print

(int

&val)

intmain()

cout << endl;

//第二種遍歷方法

for(vector<

int>

::iterator beg=v.

begin()

;beg!=v.

end(

);beg++

) cout <<

*beg <<

" ";

cout << endl;

//第三種遍歷方法 利用stl提供的遍歷演算法

for_each

(v.begin()

, v.

end(

), print)

;//傳入輸出函式的位址

system

("pause");

return0;

}

vector存放內建資料型別(2)

容器 vector 演算法 for each 迭代器 vector iterator 1 include 2 include 3 include 4 using namespace std 56 為第三種遍歷方式提供函式名 7void myprint int val 811 12 vector存放內...

Vector容器中存放結構體型別的變數

如果要在vector容器中存放結構體型別的變數,經常見到兩種存放方式.方式一 放入這個結構體型別變數的副本。方式二 放入指向這個結構體型別變數的指標。假設結構體型別變數是這樣的,cpp view plain copy print?typedef struct student studentinfo ...

vector容器中存放結構體型別的變數

如果要在vector容器中存放結構體型別的變數,經常見到兩種存放方式.方式一 放入這個結構體型別變數的副本。方式二 放入指向這個結構體型別變數的指標。假設結構體型別變數是這樣的,cpp view plain copy print?typedef struct student studentinfo ...