const wchar_t* pChar = L"asdasd";
map<const wchar_t*, int > mapData;
mapData.find(L"Father");
map<const wchar_t*, int > mapData;
mapData.insert(make_pair(L"Father", 0));
mapData.insert(make_pair(L"Mother", 1));
mapData.insert(make_pair(L"Brother", 2));
mapData.insert(make_pair(L"Sister", 3));
map<const wchar_t*, int >::iterator iter = mapData.find(L"Father");
iter->first;
iter->second;
wchar_t szName[20] = L"Father";
mapData.find(szName);
class Str
{
private:
wchar_t* m_pStr; // 1
int m_MaxLength; // 2
int m_Length; // 3
public:
int Length() { return m_Length; } // 4
const wchar_t* GetStr() { return m_pStr; } // 5
private:
void Realloc(); // 6
public:
Str();
Str(const wchar_t* _str);
~Str();
};
// 1
Str::Str()
: m_pStr(nullptr)
, m_MaxLength(10)
, m_Length(0)
{
m_pStr = new wchar_t[m_MaxLength + 1];
}
// 2
Str::Str(const wchar_t* _str)
: m_pStr(nullptr)
, m_MaxLength(10)
, m_Length(0)
{
m_pStr = new wchar_t[m_MaxLength + 1];
(*this) = _str;
}
// 3
Str::~Str()
{
if (nullptr != m_pStr)
delete m_pStr;
}
void Str::Realloc()
{
// 수용 공간을 2배로 확장하기
m_MaxLength *= 2;
// 새로운 공간을 만들어낸다.
wchar_t* pNew = new wchar_t[m_MaxLength + 1];
// 원래 있던 데이터를 새로운곳으로 옮긴다.
for (int i = 0; i < m_Length; ++i)
{
pNew[i] = m_pStr[i];
}
pNew[m_Length] = '\0';
// 기존 공간을 해제한다.
delete m_pStr;
// 새로운 공간을 가리킨다.
m_pStr = pNew;
}
void Str::operator=(const wchar_t* _str)
{
// 입력되려는 문자열의 문자 개수(길이) 파악
int len = 0;
while ('\0' != _str[len]) { ++len; }
// 입력되려는 문자열의 길이가 최대 수용개수를 넘어서면 저장 공간 확장
while (m_MaxLength < len)
{
Realloc();
}
// 입력 문자열의 값을, 힙 공간으로 하나씩 옮기기
int i = 0;
for (; i < len; ++i)
{
m_pStr[i] = _str[i];
}
// 마지막에 널문자로 막기
m_pStr[i] = '\0';
// 문자열 길이 갱신(입력된 문자열 길이로)
m_Length = len;
}
Str Str::operator+(const Str& _string)
{
Str strNew;
strNew = m_pStr;
strNew += _string.m_pStr;
return strNew;
}
void Str::operator+=(const wchar_t* _Str)
{
// 뒤에 붙을 문자열의 문자 개수(길이) 파악
int len = 0;
while ('\0' != _Str[len]) { ++len; }
// 원래 문자열 길이 + 새로 뒤에 붙을 문자열의 길이가 최대 저장 크기를 벗어나는지 확인
while (m_MaxLength < m_Length + len)
{
Realloc();
}
// 뒤에붙을 문자열을 가져오기
for (int i = 0; i < len; ++i)
{
m_pStr[i + m_Length] = _Str[i];
}
// 저장하고 있는 문자열 길이 갱신
m_Length += len;
m_pStr[m_Length] = '\0';
}
abc /0
이였던거에 def를 저장하면 /0
자리에 d
뒤에 e
뒤에 f
하고 뒤에 /0
한다. map<Str, int> mapString;
mapString.insert(make_pair(L"Father", 0));
mapString.insert(make_pair(L"Mother", 1));
mapString.insert(make_pair(L"Brother", 2));
mapString.insert(make_pair(L"Sister", 3));
Str::Str(const wchar_t* _str)
: m_pStr(nullptr)
, m_MaxLength(10)
, m_Length(0)
{
m_pStr = new wchar_t[m_MaxLength + 1];
(*this) = _str;
}
public:
void operator = (const wchar_t* _str);
Str operator+ (const Str& _string);
Str operator+ (const char* _Str);
void operator +=(const wchar_t* _Str);
bool operator ==(const Str& _Other) const;
bool operator !=(const Str& _Other) const;
bool operator <(const Str& _Other) const;
bool operator >(const Str& _Other) const;
bool operator <=(const Str& _Other) const;
bool operator >=(const Str& _Other) const;
bool Str::operator==(const Str& _Other) const
{
return false;
}
bool Str::operator!=(const Str& _Other)const
{
return false;
}
bool Str::operator<(const Str& _Other)const
{
return false;
}
bool Str::operator>(const Str& _Other)const
{
return false;
}
bool Str::operator<=(const Str& _Other)const
{
return false;
}
bool Str::operator>=(const Str& _Other)const
{
return false;
}
==
는 일대일 매칭해보고 다 같으면 같다, 아니면 틀리다.#include <iostream>
#include "Str.h"
#include <map>
using std::map;
using std::make_pair;
int main()
{
const wchar_t* pChar = L"asdasd";
map<const wchar_t*, int> mapData;
mapData.insert(make_pair(L"Father", 0));
mapData.insert(make_pair(L"Mother", 1));
mapData.insert(make_pair(L"Brother", 2));
mapData.insert(make_pair(L"Sister", 3));
map<const wchar_t*, int>::iterator iter = mapData.find(L"Father");
iter->first;
iter->second;
wchar_t szName[20] = L"Father";
mapData.find(szName);
map<Str, int> mapString;
mapString.insert(make_pair(L"Father", 0));
mapString.insert(make_pair(L"Mother", 1));
mapString.insert(make_pair(L"Brother", 2));
mapString.insert(make_pair(L"Sister", 3));
Str str(L"Father");
return 0;
}
#pragma once
class Str
{
private:
wchar_t* m_pStr; // 동적할당한 문자열의 주소
int m_MaxLength; // 문자열을 저장할 수 있는 최대 길이
int m_Length; // 문자열의 길이
public:
int Length() { return m_Length; }
const wchar_t* GetStr() { return m_pStr; }
private:
void Realloc();
// 연산자 오버로딩
public:
void operator = (const wchar_t* _str);
Str operator+ (const Str& _string);
Str operator+ (const char* _Str);
void operator +=(const wchar_t* _Str);
bool operator ==(const Str& _Other) const;
bool operator !=(const Str& _Other) const;
bool operator <(const Str& _Other) const;
bool operator >(const Str& _Other) const;
bool operator <=(const Str& _Other) const;
bool operator >=(const Str& _Other) const;
public:
Str();
Str(const wchar_t* _str);
~Str();
};
#include "Str.h"
#include <iostream>
Str::Str()
: m_pStr(nullptr)
, m_MaxLength(10)
, m_Length(0)
{
m_pStr = new wchar_t[m_MaxLength + 1];
}
Str::Str(const wchar_t* _str)
: m_pStr(nullptr)
, m_MaxLength(10)
, m_Length(0)
{
m_pStr = new wchar_t[m_MaxLength + 1];
(*this) = _str;
}
Str::~Str()
{
if (nullptr != m_pStr)
delete m_pStr;
}
void Str::Realloc()
{
m_MaxLength *= 2;
wchar_t* pNew = new wchar_t[m_MaxLength + 1];
for (int i = 0; i < m_Length; ++i)
{
pNew[i] = m_pStr[i];
}
pNew[m_Length] = '\0';
delete m_pStr;
m_pStr = pNew;
}
void Str::operator=(const wchar_t* _str)
{
int len = 0;
while ('\0' != _str[len]) { ++len; }
while (m_MaxLength < len)
{
Realloc();
}
int i = 0;
for (; i < len; ++i)
{
m_pStr[i] = _str[i];
}
m_pStr[i] = '\0';
m_Length = len;
}
Str Str::operator+(const Str& _string)
{
Str strNew;
strNew = m_pStr;
strNew += _string.m_pStr;
return strNew;
}
Str Str::operator+(const char* _Str)
{
Str strNew;
return strNew;
}
void Str::operator+=(const wchar_t* _Str)
{
int len = 0;
while ('\0' != _Str[len]) { ++len; }
while (m_MaxLength < m_Length + len)
{
Realloc();
}
for (int i = 0; i < len; ++i)
{
m_pStr[i + m_Length] = _Str[i];
}
m_Length += len;
m_pStr[m_Length] = '\0';
}
bool Str::operator==(const Str& _Other) const
{
return false;
}
bool Str::operator!=(const Str& _Other)const
{
return false;
}
bool Str::operator<(const Str& _Other)const
{
return false;
}
bool Str::operator>(const Str& _Other)const
{
return false;
}
bool Str::operator<=(const Str& _Other)const
{
return false;
}
bool Str::operator>=(const Str& _Other)const
{
return false;
}
1차 24.01.10
2차 24.01.11
3차 24.01.12
4차 24.01.15
5차 24.01.16