-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest11.cpp
executable file
·95 lines (81 loc) · 1.74 KB
/
test11.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include"all.hpp"
#include"stringcl.hpp"
#include<stdio.h>
string::string()
{ p =new srep ; p->s = 0 ;}
string::string(const string & x)
{ x.p->n ++ ; p =x.p ; }
string::string(const char *s)
{
p= new srep ;
p-> s = new char[strlen(s) + 2] ;
strcpy(p->s , s ) ;
}
string::string( char *s)
{ p= new srep ; p-> s = new char[strlen(s) + 2] ; strcpy(p->s , s ) ;}
string::~string()
{
if( --p->n == 0){
delete[] p->s ;
delete p ;
}
}
string & string::operator=(const char *s )
{
if(p-> n > 1 ){
p-> n -- ;
p = new srep ;
}else
delete[] p->s ;
p->s = new char[strlen(s)+2] ;
strcpy(p->s , s ) ;
return *this ;
}
string & string::operator=(const string &x )
{
x.p-> n ++ ; //protect against st = st
if(--p->n == 0)
{ delete[] p->s ; delete p ; }
p = x.p ;
return *this ;
}
ostream & operator<<(ostream & s , const string & x )
{
return s << x.p->s ;// return s << x.p->s << "[ " << x.p->n << "]\n";
}
istream & operator>>(istream & s ,const string & x )
{
char buf[256] ;
gets(buf) ;
//s >> buf ;//unsafe might overflow
x = buf ; // overload =
// err_class_calc << "echo : " << x << '\n' ;
return s ;
}
void main(void)
{
cvContain cv ;
clrscr();
tokenContainCls t1;
t1.nameVar = "ali";
t1.line = 1 ;
cv.push(t1 , 1) ;
t1.nameVar = "ahmad";
t1.line = 2 ;
cv.push(t1 , 2) ;
t1.nameVar = "ahmadreza";
t1.line = 13 ;
cv.push(t1 , 3) ;
t1.nameVar = "alireza";
t1.line = 18 ;
cv.push(t1 , 4) ;
t1.nameVar = "ahmad";
t1.line = 2 ;
cout<< cv.search(t1) <<endl ;
t1.nameVar = "ali";
t1.line = 1 ;
cout<< cv.search(t1) <<endl ;
t1.nameVar = "alireza";
t1.line = 18 ;
cout<< cv.search(t1) <<endl ;
}