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:26] – [Διάτρεξη] gthanos | cpp:strings [2017/05/08 06:00] – [Μεταβολή του αλφαριθμητικού] gthanos | ||
---|---|---|---|
Line 153: | Line 153: | ||
string& operator+= (const char* s); | string& operator+= (const char* s); | ||
string& operator+= (char c);</ | string& operator+= (char c);</ | ||
- | | <code cpp></ | + | | <code cpp>string& append (const string& str); |
- | | <code cpp></ | + | string& append (const char* str);</ |
- | | <code cpp></ | + | | <code cpp>string& assign (const string& str); |
- | | <code cpp></ | + | string& assign (const char* str)</ |
- | | <code cpp></ | + | | <code cpp>string& insert (size_t pos, const string& str); |
- | | <code cpp></ | + | string& insert (size_t pos, const char* str);</ |
- | | <code cpp></ | + | | <code cpp>string& erase (size_t pos = 0, size_t len = npos); |
- | | <code cpp></ | + | iterator erase (iterator p); |
+ | iterator erase (iterator first, iterator last);</ | ||
+ | | <code cpp>string& replace (size_t pos, size_t len, const string& str); | ||
+ | string& replace (size_t pos, size_t len, const char* s); | ||
+ | string& replace (size_t pos, size_t len, const string& str, | ||
+ | | ||
+ | </ | ||
+ | | <code cpp>void swap (string& | ||
+ | <code cpp append.cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | using namespace std; | ||
- | === Σύγκριση, | + | int main () { |
+ | string str=" | ||
+ | string str2=" "; | ||
+ | char[] str3=" | ||
+ | string str4 = " | ||
+ | |||
+ | str+=str2; | ||
+ | str.append(str3); | ||
+ | str.append(str4); | ||
+ | cout << str; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code cpp replace.cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | using namespace std; | ||
+ | |||
+ | int main () { | ||
+ | string base=" | ||
+ | string str2=" | ||
+ | string str3=" | ||
+ | string str4=" | ||
+ | |||
+ | string str=base; | ||
+ | str.replace(9, | ||
+ | str.replace(19, | ||
+ | str.replace(8, | ||
+ | cout << str << endl; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code cpp chicken.cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | using namespace std; | ||
+ | |||
+ | main (){ | ||
+ | string chicken (" | ||
+ | string egg (" | ||
+ | cout << " | ||
+ | cout << " and egg comes from " << egg << endl; | ||
+ | |||
+ | chicken.swap (egg); | ||
+ | cout << "After the swap, chicken comes from " << chicken; | ||
+ | cout << " and egg comes from " << egg << endl; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Σύγκριση, | ||
| <code cpp></ | | <code cpp></ |
cpp/strings.txt · Last modified: 2021/04/27 04:45 (external edit)