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:36] – [Η κλάση 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 είναι οι εξής: | ||
- | |||
- | Δείτε το παρακάτω παράδειγμα χρήσης της κλάσης //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; | ||
- | } | ||
- | </ | ||
- | |||
- | |||
- | |||
- | |||
cpp/strings.1493739400.txt.gz · Last modified: 2017/05/02 14:36 (external edit)