This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | Next revision Both sides next revision | ||
|
cpp:strings [2017/05/08 05:51] gthanos [Μεταβολή του αλφαριθμητικού] |
cpp:strings [2017/05/08 06:00] gthanos [Μεταβολή του αλφαριθμητικού] |
||
|---|---|---|---|
| Line 167: | Line 167: | ||
| | | ||
| </ | </ | ||
| - | | <code cpp></ | + | | <code cpp>void swap (string& |
| - | | | + | |
| - | | <code cpp></ | + | < |
| + | # | ||
| + | #include < | ||
| + | using namespace std; | ||
| + | |||
| + | int main () { | ||
| + | string str=" | ||
| + | string str2=" "; | ||
| + | char[] str3=" | ||
| + | string str4 = " | ||
| + | |||
| + | str+=str2; | ||
| + | str.append(str3); | ||
| + | str.append(str4); | ||
| + | | ||
| + | } | ||
| + | </ | ||
| <code cpp replace.cpp> | <code cpp replace.cpp> | ||
| Line 187: | Line 203: | ||
| str.replace(8, | str.replace(8, | ||
| cout << str << endl; | 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; | ||
| } | } | ||
| </ | </ | ||