CArr<float> arr_float;
std::vector<float> vecFloat;
vecFloat.push_back(1.1f);
std::vector<int> vecInt;
std::vector<float> vecFloat;
vecFloat.push_back(1.1f);
std::vector<int> vecInt;
vecInt.reserve(100);
std::vector<int> vecInt;
vecInt.resize(100);
vecInt[10] = 20;
vecInt.push_back(100); // 1
vecInt[10] = 20; // 2
vecInt.reserve(100);
vecInt.at(10) = 11;
std::vector<int> g_vecInt;
int main()
{
std::vector<int> vecTemp;
vecTemp = g_vecInt; // 1
g_vecInt.swap(vecTemp); // 2
return 0;
}
std::vector<short> vecShort;
for (int i = 0; i < 100; ++i)
{
// 명시적으로 short변경.
vecShort.push_back((short)(i + 1)); // 1
}
for (size_t i = 0; i < vecShort.size(); ++i) // 2
{
//printf("%d\n", vecShort.at(i)); // 3.1
//cout << vecShort.at(i) << endl; // 3.2
cout << vecShort[i] << endl; // 3.3
}
list<short> shortList;
for (int i = 0; i < 100; ++i)
{
shortList.push_back(short(i + 1));
}
for (size_t i = 0; i < shortList.size(); ++i)
{
//printf("%d\n", shortList.at(i));
//cout << shortList.at(i) << endl;
//cout << shortList[i] << endl; // 1
//cout << shortList.at(i) << endl; // 2
//cout << shortList << endl;
}
std::vector<short> vecShort;
for (int i = 0; i < 100; ++i)
{
// 명시적으로 short변경.
vecShort.push_back((short)(i + 1));
}
vector<short>::iterator vec_iter = vecShort.begin();
for (; vec_iter != vecShort.end(); ++vec_iter)
{
cout << *vec_iter << endl;
}
list<short> shortList;
for (int i = 0; i < 100; ++i)
{
shortList.push_back(short(i + 1));
}
list<short>::iterator list_iter = shortList.begin();
for (; list_iter != shortList.end(); ++list_iter)
{
cout << *list_iter << endl;
}
vector<short>::iterator vec_iter = vecShort.begin(); // 1
for (; vec_iter != vecShort.end(); ++vec_iter) // 2
{
cout << *vec_iter << endl; // 3
}
#include <set>
using std::set;
int main()
{
set<int> intset;
for (int i = 0; i < 100; ++i)
{
intset.insert(i);
}
set<int>::iterator setiter = intset.begin();
for (; setiter != intset.end(); ++setiter)
{
cout << *setiter << endl;
}
}
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <vector>
using std::vector;
#include <list>
using std::list;
#include <set>
using std::set;
#include <map>
using std::map;
using std::make_pair;
#include "CArr.h"
class CTest
{
public:
CTest()
{}
~CTest()
{}
};
std::vector<int> g_vecInt;
int main()
{
int size = sizeof(CTest);
CTest* pArr = (CTest*)malloc(16);
free(pArr);
CTest* pArr1 = new CTest;
delete pArr1;
CTest* pArr2 = new CTest[10];
delete[] pArr2;
CArr<int> arr;
CArr<int> arr1;
arr.push_back(10);
arr.push_back(20);
arr1.push_back(30);
int value = 0;
value = arr.at(0);
value = arr.at(1);
value = arr.at(2);
CArr<float> arr_float;
arr_float.push_back(1.1f);
arr_float.push_back(2.2f);
arr_float.push_back(3.3f);
float fvalue = 0;
fvalue = arr_float.at(0);
fvalue = arr_float.at(1);
fvalue = arr_float.at(2);
std::vector<float> vecFloat;
vecFloat.push_back(1.1f);
fvalue = vecFloat.at(0);
fvalue = vecFloat[0];
vecFloat.size();
vecFloat.capacity();
vecFloat.reserve(10);
vecFloat.resize(10);
std::vector<int> vecInt;
vecInt.reserve(100);
//vecInt.at(10) = 11;
//vecInt.resize(110);
//vecInt[10] = 20;
std::vector<int> vecTemp;
vecTemp = g_vecInt;
g_vecInt.swap(vecTemp);
std::vector<short> vecShort;
for (int i = 0; i < 100; ++i)
{
vecShort.push_back((short)(i + 1));
}
//for (size_t i = 0; i < vecShort.size(); ++i)
//{
// //printf("%d\n", vecShort.at(i));
// //cout << vecShort.at(i) << endl;
// cout << vecShort[i] << endl;
//}
vector<short>::iterator vec_iter = vecShort.begin();
for (; vec_iter != vecShort.end(); ++vec_iter)
{
cout << *vec_iter << endl;
}
list<short> shortList;
for (int i = 0; i < 100; ++i)
{
shortList.push_back(short(i + 1));
}
//for (size_t i = 0; i < shortList.size(); ++i)
//{
// //printf("%d\n", vecShort.at(i));
// //cout << vecShort.at(i) << endl;
// //cout << shortList << endl;
//}
list<short>::iterator list_iter = shortList.begin();
for (; list_iter != shortList.end(); ++list_iter)
{
cout << *list_iter << endl;
}
set<int> intset;
for (int i = 0; i < 100; ++i)
{
intset.insert(i);
}
set<int>::iterator setiter = intset.begin();
for (; setiter != intset.end(); ++setiter)
{
cout << *setiter << endl;
}
return 0;
}
#pragma once
// 클래스 템플릿
template<typename T>
class CArr
{
private:
T* m_pData;
int m_MaxCount;
int m_CurCount;
public:
//
void push_back(const T& _Data); // 1
private:
void Realloc();
public:
int size() { return m_CurCount; }
int capacity() { return m_MaxCount; }
T at(int _Idx) { return m_pData[_Idx]; }
T& operator[](int _Idx) { return m_pData[_Idx]; }
public:
CArr();
~CArr();
};
template<typename T>
CArr<T>::CArr()
: m_pData(nullptr)
, m_CurCount(0)
, m_MaxCount(2)
{
m_pData = new T[m_MaxCount];
}
template<typename T>
CArr<T>::~CArr()
{
delete[] m_pData;
}
template<typename T>
void CArr<T>::push_back(const T& _Data) // 1
{
if (m_MaxCount <= m_CurCount)
{
Realloc();
}
m_pData[m_CurCount++] = _Data;
}
template<typename T>
void CArr<T>::Realloc()
{
m_MaxCount *= 2;
T* pNew = new T[m_MaxCount];
for (int i = 0; i < m_CurCount; ++i)
{
pNew[i] = m_pData[i];
}
delete[] m_pData;
m_pData = pNew;
}
1차 23.12.27
2차 23.12.28
3차 23.12.29
4차 24.01.02
5차 24.01.03