31 lines
688 B
C++
31 lines
688 B
C++
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
template <typename T>
|
||
|
void print(vector<T> &v)
|
||
|
{
|
||
|
typename vector<T>::iterator it = v.begin();
|
||
|
while (it != v.end())
|
||
|
{
|
||
|
cout << *it << " ";
|
||
|
it++;
|
||
|
}
|
||
|
cout << endl;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
int arr1[5] = {1, 2, 3, 4, 5};
|
||
|
vector<double> v1(arr1, arr1 + 5);
|
||
|
|
||
|
print(v1);
|
||
|
|
||
|
cout << "first element is: " << v1.front() << endl;
|
||
|
cout << "first element addr is: " << &v1.front() << endl; // 与 day9/d7.cpp 中的 first addr 不同
|
||
|
cout << "last element is: " << v1.back() << endl;
|
||
|
cout << "last element addr is: " << &v1.back() << endl; // 与 day9/d7.cpp 中的 first addr 不同
|
||
|
|
||
|
return 0;
|
||
|
}
|