vector-front

////////////////////////////////////////
//      2018/04/16 15:46:02
//      vector-front

#include <iostream>
#include <vector>
#include <string>
#include <iterator>

using namespace std;

template<class T, class D>
class Member
{
private:
    T name;
    D sal;
public:
    Member(T t, D d) :name(t), sal(d){}
    void print();
};

template<class T, class D>
void Member<T,D>::print(){
    cout << name << " " << sal << endl;
}
// ========================

int main(){
    typedef Member<string, double> M;
    vector<M> v;
    v.push_back(M("Linda", 75000));
    v.push_back(M("Robert",60000));
    vector<M>::iterator it = v.begin();
    cout << "Entir vector:" << endl;
    while (it != v.end()){
        (it++)->print();
    }
    cout << endl;
    cout << "return from front()" << endl;
    v.front().print();
    return 0;
}

/*
OUTPUT:
Entir vector:
Linda 75000
Robert 60000

return from front()
Linda 75000
*/
阅读更多

扫码向博主提问

小小妖妖

非学,无以致疑;非问,无以广识
去开通我的Chat快问
版权声明:我是一只快乐的小妖精 https://blog.csdn.net/qwq1503/article/details/79965331
个人分类: STL
所属专栏: C++STL样列
上一篇vector-erase
下一篇vector-insert
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭