Advertisement
TheWhiteFang

String tips

Dec 17th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. //http://pastebin.com/u/TheWhiteFang
  2. //sasi punya
  3. #include <iostream>
  4. #include <string.h>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     // C Style
  11.     char strArray[32] = {0};
  12.     strcpy(strArray, "Electronics Engineering");
  13.     int length = strlen(strArray);
  14.  
  15.     cout << "Before Erase (C style): " << strArray << endl;
  16.     for(int i = 9; i < length; i++)
  17.     {
  18.         strArray[i] = strArray[i+1];
  19.     }
  20.     cout << "After Erase (C style): " << strArray << endl;
  21.  
  22.     // C++ Style
  23.     string str01 = "Electronics Engineering";
  24.     cout << "\nBefore Erase (C++ stye): " << str01 << endl;
  25.     str01.erase(str01.begin() + 9);
  26.     cout << "After Erase (C++ stye): " << str01 << endl;
  27.  
  28.     str01 = "L" + str01;
  29.     cout << "\nAfter add at beginning (C++ style): " << str01 << endl;
  30.     str01 = str01 + "S";
  31.     cout << "After add at end (C++ style): " << str01 << endl << endl;
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement