Skip to content

Commit 2d6d802

Browse files
committed
using std::string with name
1 parent 33c4256 commit 2d6d802

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

BinaryFile/student.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,8 @@ void Student::setAge(int age) { this->age = age; }
77
void Student::setAge(short age) { this->age = age; }
88
void Student::setAge(unsigned short age) { this->age = age; }
99

10-
void Student::setName(std::string &name) {
11-
if (name.length() < 50) {
12-
std::strcpy(this->name, name.c_str());
13-
}
14-
}
15-
void Student::setName(const char *name) {
16-
if (std::strlen(name) < 50) {
17-
std::strcpy(this->name, name);
18-
}
19-
}
10+
void Student::setName(std::string &name) { this->name = name; }
11+
void Student::setName(const char *name) { this->name = std::string(name); }
2012

2113
std::string Student::whoami() const {
2214
std::stringstream s;

BinaryFile/student.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Student {
44
private:
5-
char name[50];
5+
std::string name;
66
unsigned short age;
77

88
public:

0 commit comments

Comments
 (0)