Commit 91ab86e0 authored by Tianyi Liu's avatar Tianyi Liu
Browse files

fix: string bugs

Showing with 7 additions and 7 deletions
+7 -7
......@@ -28,10 +28,10 @@ String::String(int length):_capacity(length+1),_length(length){
}
String::String(const String& b){
_capacity=b._length;
_capacity=b._length+1;
_length=b._length;
data=new char[_length];
memcpy(data,b.data,_length);
data=new char[_capacity];
memcpy(data,b.data,_capacity);
}
char* String::c_str()const{
......@@ -39,11 +39,11 @@ char* String::c_str()const{
}
int String::length()const{
return _length-1;
return _length;
}
int String::size()const{
return _length-1;
return _length;
}
String String::operator+(const String& b)const{
......
......@@ -6,8 +6,8 @@
class String{
public:
const static int __INIT_CAPACITY=10;
int _capacity;
int _length;
int _capacity; // current vector capacity
int _length; // length without '0' in the end
char* data;
String(const char* str);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment