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 revisionBoth sides next revision
cpp:strings [2017/05/08 05:51] – [Μεταβολή του αλφαριθμητικού] gthanoscpp:strings [2017/05/08 06:00] – [Μεταβολή του αλφαριθμητικού] gthanos
Line 167: Line 167:
                  size_t subpos, size_t sublen);                  size_t subpos, size_t sublen);
 </code>  | Αντικαθιστά το υφιστάμενο //string// με το νέο //str// ξεκινώντας από την θέση //pos// του //string// και για μήκος //len//  | </code>  | Αντικαθιστά το υφιστάμενο //string// με το νέο //str// ξεκινώντας από την θέση //pos// του //string// και για μήκος //len//  |
-|  <code cpp></code>   +|  <code cpp>void swap (string& str);</code> Ανταλλάσει αμοιβαία το περιεχόμενο του τρέχοντος //string// με το περιοχόμενο του //string str//.  
-|  <code cpp></code>  |   | + 
- <code cpp></code>    |+<code cpp append.cpp> 
 +#include <iostream> 
 +#include <string> 
 +using namespace std; 
 + 
 +int main () { 
 +  string str="Hello"; 
 +  string str2=" "; 
 +  char[] str3="World"; 
 +  string str4 = "!\n"; 
 + 
 +  str+=str2; 
 +  str.append(str3); 
 +  str.append(str4); 
 +  cout << str; 
 +
 +</code>
  
 <code cpp replace.cpp> <code cpp replace.cpp>
Line 187: Line 203:
   str.replace(8,10,"just a");     // "this is just a phrase."     (3)   str.replace(8,10,"just a");     // "this is just a phrase."     (3)
   cout << str << endl;   cout << str << endl;
 +}
 +</code>
 +
 +<code cpp chicken.cpp>
 +#include <iostream>
 +#include <string>
 +using namespace std;
 +
 +main (){
 +  string chicken ("chicken");
 +  string egg ("egg");
 +  cout << "Before the swap, chicken comes from " << chicken;
 +  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> </code>
cpp/strings.txt · Last modified: 2021/04/27 04:45 (external edit)