include stdafx using namespace std char Stroka GetStr void return pCh

 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
41
42
43
44
45
46
47
48
#include <stdafx.h>
using namespace std;
char* Stroka::GetStr(void)
{
return pCh;
}
int Stroka::GetLen(void)
{
if(strlen(pCh)==0){
cout<<"the string's length is 0"<<endl;
return 0;
}
return strlen(pCh);
}
void Stroka::Print()
{
cout<<"\n"<<pCh;
}
Stroka ::Stroka() //конструктор по умолчанию
{
len =0;
pCh= new char[len+1];
pCh='\0';
cout<<"Stroka::Stroka () is working"<<endl;
}
Stroka::Stroka(char *s) //конструктор,принимающий Си-строку
{
len=strlen(s);
pCh=new char[len+1];
strcpy(pCh,s);
pCh[len]=0;
cout<<"Stroka::Stroka(char *s) is working"<<endl;
}
Stroka::~Stroka() //деструктор
{
delete[] pCh;
cout<<"Stroka::~Stroka() is working"<<endl;
}
Stroka::Stroka(Stroka & from) //конструктор копирования
{
char *tmpStr=from.GetStr();
int L=from.GetLen();
pCh=new char[L+1];
strcpy(pCh,tmpStr);
cout<<"Stroka::Stroka(Stroka &from)"<<endl;
}