cpp:strings
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cpp:strings [2017/05/02 15:51] – [Μέθοδοι] gthanos | cpp:strings [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 27: | Line 27: | ||
| <code cpp>char *strstr(const char *haystack, const char *needle);</ | | <code cpp>char *strstr(const char *haystack, const char *needle);</ | ||
| <code cpp>char *strstr(const char *haystack, const char *needle);</ | | <code cpp>char *strstr(const char *haystack, const char *needle);</ | ||
- | |||
- | ===== Η κλάση String ===== | ||
- | |||
- | Η // | ||
- | |||
- | Οι βασικές μέθοδοι της κλάσης string είναι οι εξής: | ||
- | |||
- | Δείτε το παρακάτω παράδειγμα χρήσης της κλάσης //string//: | ||
- | <code cpp string.cpp> | ||
- | int main(int argc, char *argv[]) { | ||
- | string str = "Hello World!"; | ||
- | cout << str << endl; | ||
- | str.append(" | ||
- | cout << str << endl; | ||
- | | ||
- | str = "Hello Wordl!"; | ||
- | str += " How are you?"; | ||
- | cout << str << endl; | ||
- | } | ||
- | </ | ||
- | |||
- | ==== Κατασκευαστές ==== | ||
- | |||
- | | default constructor | ||
- | | copy constructor | ||
- | | substring constructor | string (const string& str, size_t pos, size_t len = npos); | | ||
- | | from c-string constructor | ||
- | | from c-string sequence | string (const char* s, size_t n); | | ||
- | | fill with c | string (size_t n, char c); | | ||
- | |||
- | Παράδειγμα χρήσης κατασκευαστών | ||
- | <code cpp strings_constructor.cpp> | ||
- | #include < | ||
- | using namespace std; | ||
- | |||
- | int main() { | ||
- | string str = "Hello World!"; | ||
- | string copy(str); | ||
- | string substring(str, | ||
- | const char *p = str.c_str(); | ||
- | string fromCString(p); | ||
- | string fromCSequence(p, | ||
- | string fillwithDollars(5, | ||
- | | ||
- | cout << str << endl; | ||
- | cout << copy << endl; | ||
- | cout << substring << endl; | ||
- | cout << p << endl; | ||
- | cout << fromCString << endl; | ||
- | cout << fromCSequence << endl; | ||
- | cout << fillwithDollars << endl; | ||
- | } | ||
- | </ | ||
- | |||
- | ==== Μέθοδοι ==== | ||
- | |||
- | === Χωρητικότητα και μέγεθος αλφαριθμητικού === | ||
- | |||
- | | size_t size() const; | ||
- | | size_t length() const; | ||
- | | size_t capacity() const; | ||
- | | void resize (size_t n); και | ||
- | | void resize (size_t n, char c); | Επεκτείνεται το αλφαριθμητικό ώστε να έχει νέο μέγεθος '' | ||
- | | void reserve (size_t n = 0); | Μεταβάλλει τη χωρητικότητα του αλφαριθμητικού. | | ||
- | | void clear(); | Διαγράφει τα περιεχόμενα του αλφαριθμητικού | ||
- | | bool empty() const | Επιστρέφει //true// εάν το αλφαριθμητικό είναι άδειο. | | ||
- | |||
- | === Πρόσβαση σε χαρακτήρες του αλφαριθμητικού === | ||
- | |||
- | === Μεταβολή του αλφαριθμητικού === | ||
- | |||
- | === Σύγκριση, | ||
- | |||
- | |||
- | === Διάτρεξη === | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
cpp/strings.1493740280.txt.gz · Last modified: 2017/05/02 14:51 (external edit)