Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://pastebin.com/u/TheWhiteFang
- //cuz strings r fun -.-'
- #include <iostream>
- #include <string.h>
- #include <string>
- using namespace std;
- int main()
- {
- //// C Style
- //char strArray[32] = {0};
- //strcpy(strArray, "Electronics Engineering");
- //int length = strlen(strArray);
- //cout << "Before Erase (C style): " << strArray << endl;
- //for(int i = 9; i < length; i++)
- //{
- // strArray[i] = strArray[i+1];
- //}
- //cout << "After Erase (C style): " << strArray << endl;
- // C++ Style
- string str01 = "Electronics Engineering";
- string str02;
- cout << "Original string : " << str01 << endl;
- cout << "It's lenth is " << str01.length() << endl;//lenth is 23
- str01.erase(str01.begin() + 9);
- cout << "After Erase : " << str01 << endl<<endl; //Electronis Engineeering
- str02.assign(str01);
- int cmpresult = str01.compare(str02);
- if (cmpresult == 0) cout << "str01 is similar str02\n" <<endl<<endl;
- cout << "Value of str02 after assign function: " << str02 << endl; //Electronis Engineering
- str02.erase(8, 22); //from position 8, delete upto 22
- cout << "Value after str02 erase: " << str02 << endl;//Electron
- str02.append("s are awesome");
- cout << "str02 after append: " << str02 << endl<<endl;
- cmpresult = str01.compare(0, 8, str02, 0,8);//compare Electronis Engineering with Electron with given parameters
- cout << "Result of comparison of str01 and str02: " <<cmpresult<<endl<<endl;
- str01 = "L" + str01;
- cout << "str01 add at beginning: " << str01 << endl; //LElectronis Engineering
- str01 = str01 + "S";
- cout << "str01 add at end: " << str01 << endl << endl;//LElectronis EngineeringS
- str01 = string(str01.rbegin(), str01.rend());//reverse the string
- cout << "Reversed text = " << str01 << endl; //SgnireenignE sinortceIEL
- //pending
- //append , position , etc..
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement