vector insert

phoenixKim·2022년 6월 12일
0

temp

목록 보기
9/11
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
#include <fstream>
#include <sstream>
#include <map>
#include <list>

#include <memory>

class Car
{
private : 
	int a, b;

public : 
	Car(int _a, int _b) {}
	Car() { cout << "constr" << endl; }
	~Car() { cout << "destr" << endl; }

};


class test
{
public :
	int data;
public : 
	test() = default;
	test(int i)
	{
		data = i;
		cout << "default" << endl;
	}

	test(const test &other)
	{
		data = other.data;
		cout << "copy" << endl;
	}

	test(test&& other)
	{
		data = move(other.data);
		cout << "move" << endl;
	}

	test operator=(const test& other)
	{
		data = other.data;
		return *this;
	}
};


int main()
{
	vector<test>v;

	for (int i = 0; i < 10; i++)
	{
		test t(i);
		v.push_back(t);
	}
	
	for (auto iter : v)
		cout << iter.data << endl;

	cout << "test======================" << endl;
	v.insert(begin(v), 2, 17);


	cout << "test2 " << endl;

	for (auto iter : v)
		cout << iter.data << endl;

	//vector<int> v;
	//
	//for (int i = 0; i < 10; i++)
	//{
	//	v.push_back(i);
	//}
	//
	//v.insert(begin(v), 2, 4);

}
profile
🔥🔥🔥

0개의 댓글

관련 채용 정보