cpp:strings
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
cpp:strings [2017/05/08 05:16] – [Μεταβολή του αλφαριθμητικού] gthanos | cpp:strings [2017/05/08 05:48] – [Μεταβολή του αλφαριθμητικού] gthanos | ||
---|---|---|---|
Line 107: | Line 107: | ||
Στις όλες παραπάνω περιπτώσεις εάν το //string// είναι //const// επιστρατεύεται η //const// έκδοση της συνάρτησης. | Στις όλες παραπάνω περιπτώσεις εάν το //string// είναι //const// επιστρατεύεται η //const// έκδοση της συνάρτησης. | ||
- | === Διάτρεξη === | + | ==== Διάτρεξη |
- | | <code cpp></ | + | | <code cpp>iterator begin(); |
- | | <code cpp></ | + | const_iterator begin() const;</ |
- | | <code cpp></code> | + | | <code cpp>iterator end(); |
- | | <code cpp></code> | + | const_iterator end() const;</ |
- | | <code cpp></ | + | | <code cpp>reverse_iterator rbegin(); |
- | | <code cpp></code> | + | const_reverse_iterator rbegin() const;</ |
- | | <code cpp></code> | + | | <code cpp>reverse_iterator rend(); |
- | | <code cpp></ | + | const_reverse_iterator rend() const;</ |
- | | <code cpp></code> | + | |
- | | <code cpp></code> | + | === Παράδειγμα χρήσης iterator === |
- | | <code cpp></ | + | |
- | | <code cpp></ | + | |
- | | <code cpp></code> | + | |
- | | <code cpp></ | + | |
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | using namespace std; | ||
+ | |||
+ | int main (){ | ||
+ | string str = "Hello World!"; | ||
+ | for( string:: | ||
+ | cout << *it; | ||
+ | cout << endl; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Παράδειγμα χρήσης reverse_iterator === | ||
+ | |||
+ | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | using namespace std; | ||
+ | |||
+ | int main (){ | ||
+ | string str = "Hello World!"; | ||
+ | for (string:: | ||
+ | cout << *rit; | ||
+ | cout << endl; | ||
+ | } | ||
+ | </ | ||
==== Μεταβολή του αλφαριθμητικού ==== | ==== Μεταβολή του αλφαριθμητικού ==== | ||
Line 130: | Line 153: | ||
string& operator+= (const char* s); | string& operator+= (const char* s); | ||
string& operator+= (char c);</ | string& operator+= (char c);</ | ||
+ | | <code cpp> | ||
+ | string& append (const char* str);</ | ||
+ | | <code cpp> | ||
+ | string& assign (const char* str)</ | ||
+ | | <code cpp> | ||
+ | string& insert (size_t pos, const char* str);</ | ||
+ | | <code cpp> | ||
+ | iterator erase (iterator p); | ||
+ | iterator erase (iterator first, iterator last);</ | ||
+ | | <code cpp> | ||
+ | string& replace (size_t pos, size_t len, const char* s);</ | ||
| <code cpp></ | | <code cpp></ | ||
| <code cpp></ | | <code cpp></ | ||
| <code cpp></ | | <code cpp></ | ||
- | | | + | |
- | | | + | < |
- | | <code cpp></code> | + | # |
- | | <code cpp></code> | + | # |
- | | <code cpp></ | + | using namespace std; |
+ | |||
+ | int main () { | ||
+ | string base=" | ||
+ | string str2=" | ||
+ | string str3=" | ||
+ | string str4=" | ||
+ | |||
+ | string str=base; | ||
+ | str.replace(9, | ||
+ | | ||
+ | str.replace(8, | ||
+ | | ||
+ | str.replace(22, | ||
+ | |||
+ | | ||
+ | str.replace(str.begin(), | ||
+ | str.replace(str.begin(), | ||
+ | str.replace(str.begin()+8, | ||
+ | str.replace(str.begin()+12, | ||
+ | str.replace(str.begin()+11, | ||
+ | cout << str << endl; | ||
+ | } | ||
+ | </ | ||
- | === Σύγκριση, | + | ==== Σύγκριση, |
| <code cpp></ | | <code cpp></ |
cpp/strings.txt · Last modified: 2021/04/27 04:45 (external edit)