User Tools

Site Tools


cpp:strings

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
cpp:strings [2017/05/02 15:51] – [Μέθοδοι] gthanoscpp:strings [2021/04/27 05:45] gthanos
Line 27: Line 27:
 | <code cpp>char *strstr(const char *haystack, const char *needle);</code> | Επιστρέφει ένα δείκτη στην πρώτη εμφάνιση του ''needle'' στο ''heystack''. Eπιστρέφει NULL εάν δεν εμφανίζεται το ''needle'' στο ''heystack''. | | <code cpp>char *strstr(const char *haystack, const char *needle);</code> | Επιστρέφει ένα δείκτη στην πρώτη εμφάνιση του ''needle'' στο ''heystack''. Eπιστρέφει NULL εάν δεν εμφανίζεται το ''needle'' στο ''heystack''. |
 | <code cpp>char *strstr(const char *haystack, const char *needle);</code> | Επιστρέφει ένα δείκτη στην τελευταία εμφάνιση του ''needle'' στο ''heystack''. Επιστρέφει NULL εάν δεν εμφανίζεται το ''needle'' στο ''heystack''. | | <code cpp>char *strstr(const char *haystack, const char *needle);</code> | Επιστρέφει ένα δείκτη στην τελευταία εμφάνιση του ''needle'' στο ''heystack''. Επιστρέφει NULL εάν δεν εμφανίζεται το ''needle'' στο ''heystack''. |
- 
-===== Η κλάση String ===== 
- 
-Η //standard// βιβλιοθήκη της C++ διαθέτει την κλάση [[http://www.cplusplus.com/reference/string/string/|string]] η οποία έχει το πλεονέκτημα ότι δεν χρειάζεται να σας απασχολεί η δέσμευση της απαραίτητης μνήμης για την αποθήκευση των αλφαριθμητικών. 
- 
-Οι βασικές μέθοδοι της κλάσης string είναι οι εξής: 
- 
-Δείτε το παρακάτω παράδειγμα χρήσης της κλάσης //string//: 
-<code cpp string.cpp> 
-int main(int argc, char *argv[]) { 
-  string str = "Hello World!"; 
-  cout << str  << endl; 
-  str.append(" How are you?"); 
-  cout << str << endl; 
-   
-  str = "Hello Wordl!"; 
-  str += " How are you?"; 
-  cout << str << endl; 
-} 
-</code> 
- 
-==== Κατασκευαστές ==== 
- 
-| default constructor  | string(); | 
-| copy constructor  | string (const string& str);  | 
-| substring constructor | string (const string& str, size_t pos, size_t len = npos); | 
-| from c-string constructor  | string (const char* s);  | 
-| 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 <iostream> 
-using namespace std; 
- 
-int main() { 
-  string str = "Hello World!"; 
-  string copy(str);  
-  string substring(str, 0, 5); 
-  const char *p = str.c_str(); 
-  string fromCString(p); 
-  string fromCSequence(p, 8); 
-  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> 
- 
-==== Μέθοδοι ==== 
- 
-=== Χωρητικότητα και μέγεθος αλφαριθμητικού === 
- 
-| size_t size() const;   | Return size of string (public member function )  | 
-| size_t length() const;   | Μέθοδος ανάλογη της μεθόδου size  | 
-| size_t capacity() const;  | Χωρητικότητα του αλφαριθμητικού (σε bytes)  | 
-| void resize (size_t n); και  
-| void resize (size_t n, char c); | Επεκτείνεται το αλφαριθμητικό ώστε να έχει νέο μέγεθος ''n''. | 
-| void reserve (size_t n = 0);  | Μεταβάλλει τη χωρητικότητα του αλφαριθμητικού. | 
-| void clear(); | Διαγράφει τα περιεχόμενα του αλφαριθμητικού  | 
-| bool empty() const |  Επιστρέφει //true// εάν το αλφαριθμητικό είναι άδειο. | 
- 
-=== Πρόσβαση σε χαρακτήρες του αλφαριθμητικού === 
- 
-=== Μεταβολή του αλφαριθμητικού === 
- 
-=== Σύγκριση, αναζήτηση, εξαγωγή υπο-αλφαριθμητικών === 
- 
- 
-=== Διάτρεξη === 
- 
- 
- 
- 
- 
- 
- 
- 
  
  
cpp/strings.txt · Last modified: 2021/04/27 04:45 (external edit)