-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHarf-Ekleme.cpp
40 lines (38 loc) · 953 Bytes
/
Harf-Ekleme.cpp
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
32
33
34
35
36
37
38
39
40
#include<iostream>
#include<conio.h>
#include<string.h>
class MyString
{
private:
char *m_pchString;
int m_nLength;
public:
MyString(const char *pchString = "")
{
// Find the length of the string
// Plus one character for a terminator
m_nLength = strlen(pchString) + 1;
// Allocate a buffer equal to this length
m_pchString = new char[m_nLength];
// Copy the parameter into our internal buffer
strncpy(m_pchString, pchString, m_nLength);
// Make sure the string is terminated
m_pchString[m_nLength - 1] = ' bb ';
}
~MyString() // destructor
{
// We need to deallocate our buffer
delete[] m_pchString;
// Set m_pchString to null just in case
m_pchString = 0;
}
char* GetString() { return m_pchString; }
int GetLength() { return m_nLength; }
};
int main()
{
MyString cMyName("alex");
std::cout << "My name is: " << cMyName.GetString() << std::endl;
system("pause");
return 0;
} // cMyName destructor called here!