การใช้งานที่ปรับแต่งได้ง่าย ๆ ของคลาสสตริงที่เลียนแบบฟังก์ชั่นของ Std :: String รวมถึงตัววนซ้ำ
using size_type = size_t; // size_type for positions of char in cstring
using const_pointer = const_iterator;
using pointer = iterator;
using const_reverse_pointer = const_reverse_iterator;
using reverse_pointer = reverse_iterator;
String(); // default constructor
String(const String &); // copy constructor
String(const String& other, size_type pos, size_t len = npos); // substring constructor
String(String &&); // move constructor
String(const char *); // from c-string
String(const char* s, size_t n); // from buffer
String(size_t n, char c);// fill constructor
String(const const_iterator first, const const_iterator second); // range constructor
String & operator= (const String &); // copy assignment
String & operator = (String &&); // move assignment
~String();
ส่งคืน iterator/const_iterator ไปยังอักขระตัวแรก
iterator begin();
const_iterator begin() const;
ส่งคืนตัววนซ้ำ/const_iterator ชี้ไปที่อักขระที่ผ่านมาของสตริง
iterator end();
const_iterator end() const;
ส่งคืน const_iterator ชี้ไปที่อักขระตัวแรก / ตัวละครในอดีตของสตริง
const_iterator cbegin() const;
const_iterator cend() const;
ส่งคืน Reverse_iterator/const_reverse_iterator ไปยังอักขระสุดท้าย
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
ส่งคืน Reverse_iterator/const_reverse_iterator ชี้ไปที่ตัวละครในอดีตย้อนกลับของสตริง
reverse_iterator rend();
const_reverse_iterator rend() const;
ส่งคืน const_reverse_iterator ชี้ไปที่อักขระตัวละครตัวสุดท้าย / ย้อนกลับในอดีตของสตริง
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
รับอักขระของสตริง
const char & operator [] (size_type) const;
char & operator [] (size_type);
รับอักขระในสตริง
const char & at(size_type) const;
char & at(size_type);
เข้าถึงอักขระแรก
const char & front() const;
char & front();
เข้าถึงอักขระสุดท้าย
const char & back() const;
char & back();
ผนวกเข้ากับสตริง
String & operator += (const String &); // string (1)
String & operator += (const char *); // c - string (2)
String & operator += (char); // char (3)
ผนวกเข้ากับสตริง
String& append(const String& str); // string (1)
String& append(const String& str, size_type subpos, size_t sublen = npos); // substring (2)
String& append(const char* s); // c - string (3)
String& append(const char* s, size_t n); // buffer(4)
String& append(size_type n, char c); // fill(5)
String& append(const const_iterator first, const const_iterator second); // range(6)
String & push_back(char);
แทรกลงในสตริง
String& insert(size_type pos, const String& other); // string(1)
String& insert(size_type pos, const String& other, size_type subpos, size_t sublen = npos); // substring(2)
String& insert(size_type pos, const char* other); // c - string(3)
String& insert(size_type pos, const char* s, size_t n); // buffer(4)
String& insert(size_type pos, size_t n, char c); // fill(5)
void insert(iterator p, size_t n, char c); // fill(6)
iterator insert(iterator p, char c); // single character(7)
void insert(iterator p, const const_iterator first, const const_iterator last); // range(8)
ลบอักขระจากสตริง
String& erase(size_type pos = 0, size_t len = npos); // sequence(1)
iterator erase(const_iterator p); // character(2)
iterator erase(const_iterator first, const_iterator last); // range(3)
แทนที่ส่วนของสตริง
String& replace(size_type pos, size_t len, const String& other); // string(1)
String& replace(const_iterator i1, const_iterator i2, const String& other); // string(2)
String& replace(size_type pos, size_t len, const String& other, size_type subpos, size_t sublen = npos); // substring(3)
String& replace(size_type pos, size_t len, const char* s); // c - string(4)
String& replace(const_iterator i1, const_iterator i2, const char* other); // c - string(5)
String& replace(size_type pos, size_t len, const char* other, size_t n); // buffer(6)
String& replace(const_iterator i1, const_iterator i2, const char* other, size_t n); // buffer(7)
String& replace(size_type pos, size_t len, size_t n, char c); // fill(8)
String& replace(const_iterator i1, const_iterator i2, size_type n, char c); // fill(9)
String& replace(const_iterator i1, const_iterator i2, const_iterator first, const_iterator second); // range(10)
ค่าสตริงแลกเปลี่ยน
void swap(String &);
ลบตัวละครสุดท้าย
String & pop_back();
รับสตริง C เทียบเท่า
const char * c_str() const;
คัดลอกลำดับของอักขระจากสตริง
size_t copy(char* s, size_t len, size_type pos = 0) const;
ค้นหาเนื้อหาในสตริง
size_type find(const String& other, size_type pos = 0) const; //string(1)
size_type find(const char* s, size_type pos = 0) const; // c - string(2)
size_type find(const char* s, size_type pos, size_type n) const; // buffer(3)
size_type find(char c, size_type pos = 0) const; // character(4)
ค้นหาเหตุการณ์ที่เกิดขึ้นครั้งสุดท้ายในสตริง
size_type rfind(const String& other, size_type pos = npos) const; // string(1)
size_type rfind(const char* s, size_type pos = npos) const; // c - string(2)
size_type rfind(const char* s, size_type pos, size_t n) const; // buffer(3)
size_type rfind(char c, size_type pos = npos) const; // character(4)
ค้นหาอักขระในสตริง
size_type find_first_of(const String& other, size_type pos = 0) const; // string(1)
size_type find_first_of(const char* other, size_type pos = 0) const; // c - string(2)
size_type find_first_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_first_of(char c, size_type pos = 0) const; // character(4)
ค้นหาอักขระในสตริงจากตอนท้าย
size_type find_last_of(const String& other, size_type pos = String::npos) const; // string(1)
size_type find_last_of(const char* other, size_type pos = String::npos) const; // c - string(2)
size_type find_last_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_last_of(char c, size_type pos = String::npos) const; // character(4)
ค้นหาการขาดอักขระในสตริง
size_type find_first_not_of(const String& other, size_type pos = 0) const; // string(1)
size_type find_first_not_of(const char* other, size_type pos = 0) const; // c - string(2)
size_type find_first_not_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_first_not_of(char c, size_type pos = 0) const; // character(4)
ค้นหาอักขระที่ไม่จับคู่ในสตริงจากตอนท้าย
size_type find_last_not_of(const String& other, size_type pos = String::npos) const; // string(1)
size_type find_last_not_of(const char* other, size_type pos = String::npos) const; // c - string(2)
size_type find_last_not_of(const char* other, size_type pos, size_t n) const; // buffer(3)
size_type find_last_not_of(char c, size_type pos = String::npos) const; // character(4)
สร้าง Substring
String substr(size_type pos = 0, size_t len = npos) const;
ส่งคืนความยาวของสตริง
size_t length() const;
size_t size() const;
ส่งคืนขนาดสูงสุดของสตริง
size_t max_size() const;
ปรับขนาดสตริง
void resize(size_t n);
void resize(size_type n, char c);
ขนาดคืนของที่เก็บข้อมูลที่จัดสรร
size_t capacity() const;
ขอการเปลี่ยนแปลงความสามารถ
void reserve(size_t n = 0);
ล้างสตริง
void clear();
return true is String ว่างเปล่า
bool empty() const;
หดตัวให้พอดี
void shrink_to_fit();
static const size_t npos = -1; // Maximum value for size_t
การเปรียบเทียบ
// Size is compared and if equal then comapred lexicographically
friend bool operator == (const String &, const String &);
friend bool operator != (const String &, const String &);
friend bool operator < (const String &, const String &);
friend bool operator > (const String &, const String &);
friend bool operator <= (const String &, const String &);
friend bool operator >= (const String &, const String &);
แลกเปลี่ยนค่าของสองสตริง
void swap(String& x, String& y);
ผลตอบแทนสตริงที่ต่อกัน
String operator+ (const String& lhs, const String& rhs);
String operator+ (const String& lhs, const char* rhs);
String operator+ (const char* lhs, const String& rhs);
String operator+ (const String& lhs, char rhs);
String operator+ (char lhs, const String& rhs);
แทรกสตริงลงในสตรีม
std::ostream& operator<< (std::ostream& os, const _JD String& str);
แยกสตริงจากสตรีม
std::istream& operator>> (std::istream& is, _JD String& str);
รับบรรทัดจากสตรีมเป็นสตริง
std::istream& getline(std::istream& is, _JD String& str, char delim);
std::istream& getline(std::istream& is, _JD String& str);