Advertisement
TheWhiteFang

Cuz strings r fun

Dec 17th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. //http://pastebin.com/u/TheWhiteFang
  2. //cuz strings r fun -.-'
  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.     string str02;
  25.  
  26.     cout << "Original string : " << str01 << endl;
  27.     cout << "It's lenth is " << str01.length() << endl;//lenth is 23
  28.     str01.erase(str01.begin() + 9);
  29.     cout << "After Erase : " << str01 << endl<<endl; //Electronis Engineeering
  30.    
  31.     str02.assign(str01);
  32.     int cmpresult = str01.compare(str02);
  33.     if (cmpresult == 0) cout << "str01 is similar str02\n" <<endl<<endl;
  34.  
  35.  
  36.    
  37.     cout << "Value of str02 after assign function: " << str02 << endl; //Electronis Engineering
  38.     str02.erase(8, 22); //from position 8, delete upto 22
  39.     cout << "Value after str02 erase: " << str02 << endl;//Electron
  40.     str02.append("s are awesome");
  41.     cout << "str02 after append: " << str02 << endl<<endl;
  42.  
  43.     cmpresult = str01.compare(0, 8, str02, 0,8);//compare Electronis Engineering with Electron with given parameters
  44.     cout << "Result of comparison of str01 and str02: " <<cmpresult<<endl<<endl;
  45.  
  46.     str01 = "L" + str01;
  47.     cout << "str01 add at beginning: " << str01 << endl; //LElectronis Engineering
  48.     str01 = str01 + "S";
  49.    
  50.     cout << "str01 add at end: " << str01 << endl << endl;//LElectronis EngineeringS
  51.  
  52.  
  53.     str01 = string(str01.rbegin(), str01.rend());//reverse the string
  54.     cout << "Reversed text = " << str01 << endl; //SgnireenignE sinortceIEL
  55.  
  56.     //pending
  57.     //append , position , etc..
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement