본문 바로가기

Code/C C++

[C++] vector shared_ptr sample


#include <iostream>
#include <vector>
#include <string>
#include <memory>
#include <tchar.h>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    vector<shared_ptr<string>> svec;
    svec.push_back(shared_ptr<string>(new string("aaa")));
    svec.push_back(shared_ptr<string>(new string("bbb")));
    svec.push_back(shared_ptr<string>(new string("ccc")));

    for(vector<shared_ptr<string>>::iterator it = svec.begin(); it != svec.end(); it++)
        cout << **it << endl;

    vector<shared_ptr<int>> ivec;
    for(int i = 0; i < 5; i++)
        ivec.push_back(shared_ptr<int>(new int(i)));

    for(vector<shared_ptr<int>>::iterator it = ivec.begin(); it != ivec.end(); it++)
        cout << **it << endl;

    return 0;
}


'Code > C C++' 카테고리의 다른 글

[C++] polymorphism.h  (0) 2010.05.17
[C++] How to: Convert Between Various String Types  (0) 2010.05.17
[MFC] Simplified MFC Structure  (0) 2010.04.24
[MFC] Simplest MFC Program  (0) 2010.04.23
[C++] Regular Expressions Class: regex  (0) 2010.04.18