-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring.cpp
More file actions
53 lines (46 loc) · 1.04 KB
/
string.cpp
File metadata and controls
53 lines (46 loc) · 1.04 KB
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
//
// string.cpp
// Gábor nagyházi
//
// Created by Angéla Pinke on 2019. 04. 01..
// Copyright © 2019. Angéla Pinke. All rights reserved.
//
#include <iostream>
#include "string.h"
char String::operator[](size_t i){
if(i < len && i >= 0)
return pData[i];
throw("Tulindexelve");
}
char String::operator[](size_t i) const {
if(i < len && i >= 0)
return pData[i];
throw("Tulindexelve");
}
String& String::operator=(const String& s){
if(this != &s){
delete[] pData;
len = s.getSize();
pData = new char[len+1];
strcpy(pData, s.c_str());
}
return *this;
}
String& String::operator=(const char* c){
delete[] pData;
len = strlen(c);
pData = new char[len+1];
strcpy(pData, c);
return *this;
}
String& String::operator=(const char c){
delete[] pData;
len = 1;
pData = new char[len+1];
pData[0] = c;
pData[len] = '\0';
return *this;
}
std::ostream& operator<<(std::ostream& os, const String& s){
return os << s.c_str();
}