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/08 04:58] – [Η κλάση String] 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//: | ||
| - | <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; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | Οι βασικές μέθοδοι της κλάσης string είναι οι εξής: | ||
| - | |||
| - | ==== Κατασκευαστές ==== | ||
| - | |||
| - | | default constructor | ||
| - | | copy constructor | ||
| - | | substring constructor | <code cpp> | ||
| - | | from c-string constructor | ||
| - | | from c-string sequence | <code cpp> | ||
| - | | fill with c | <code cpp> | ||
| - | |||
| - | Παράδειγμα χρήσης κατασκευαστών | ||
| - | <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; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ==== Μέθοδοι ==== | ||
| - | |||
| - | === Χωρητικότητα και μέγεθος αλφαριθμητικού === | ||
| - | |||
| - | | <code cpp> | ||
| - | | <code cpp> | ||
| - | | <code cpp> | ||
| - | | <code cpp>void resize (size_t n); και | ||
| - | void resize (size_t n, char c);</ | ||
| - | | <code cpp>void reserve (size_t n = 0);</ | ||
| - | | <code cpp>void clear();</ | ||
| - | | <code cpp>bool empty() const;</ | ||
| - | |||
| - | === Πρόσβαση σε χαρακτήρες του αλφαριθμητικού === | ||
| - | |||
| - | === Μεταβολή του αλφαριθμητικού === | ||
| - | |||
| - | === Σύγκριση, | ||
| - | |||
| - | |||
| - | === Διάτρεξη === | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
cpp/strings.1494219511.txt.gz · Last modified: 2017/05/08 03:58 (external edit)
