hahahia

Vector assign 본문

Language/C++ STL

Vector assign

hahahia 2012. 3. 24. 12:03

#include <vector>

#include <iostream>

using namespace std;

void main( )

        vector<int> v1, v2, v3;

        vector<int>::iterator iter;

        v1.push_back(10);

        v1.push_back(20);

        v1.push_back(30);

        v1.push_back(40);

        v1.push_back(50);

        cout << "v1 = " ;

        for (iter = v1.begin(); iter != v1.end(); iter++)

               cout << *iter << " ";

        cout << endl;

        v2.assign(v1.begin(), v1.end()); // 할당

        cout << "v2 = ";

        for (iter = v2.begin(); iter != v2.end(); iter++)

               cout << *iter << " ";

        cout << endl;

        v3.assign(7, 4); // 벡터의 크기, 원소의

        cout << "v3 = ";

        for (iter = v3.begin(); iter != v3.end(); iter++)

               cout << *iter << " ";

        cout << endl;

}

 


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

map  (0) 2012.03.24
set  (0) 2012.03.24
vector  (0) 2012.03.24
cmath  (0) 2012.03.24
String Process  (0) 2012.03.24
Comments