티스토리 뷰

Code/C C++

[C++] vector shared_ptr sample

Hide Code 2010. 5. 15. 16:25

#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
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
글 보관함