Guest User

Untitled

a guest
Oct 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. // String Tester
  2. // Demonstrates string objects
  3.  
  4. #include <iostream>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. string word1 = "Game";
  12. string word2("Over");
  13. string word3(3, '!');
  14.  
  15. string phrase = word1 + " " + word2 + word3;
  16. cout << "The phrase is : " << phrase << "\n\n";
  17.  
  18. cout << "The phrase has " << phrase.size() << " characters in it.\n\n";
  19.  
  20. cout << "The character at position 0 is: " << phrase[0] << "\n\n";
  21.  
  22. cout << "Changing the character at position 0.\n";
  23. phrase[0] = 'L';
  24. cout << "The phrase is now: " << phrase << "\n\n";
  25.  
  26. for (unsigned int i = 0; i < phrase.size(); ++i)
  27. {
  28. cout << "Character at position " << i << " is: " << phrase[i]<< endl;
  29. }
  30.  
  31. cout << "\nThe sequence 'Over' begins at location ";
  32. cout << phrase.find("Over") << endl;
  33.  
  34. if (phrase.find("eggplant") == string::npos)
  35. {
  36. cout << "'eggplant' is not in the phrase.\n\n";
  37. }
  38.  
  39. phrase.erase(4, 5);
  40. cout << "The phrase is now: " << phrase << endl;
  41.  
  42. phrase.erase(4);
  43. cout << "The phrase is now: " << phrase << endl;
  44.  
  45. phrase.erase();
  46. cout << "The phrase is now: " << phrase << endl;
  47.  
  48. if (phrase.empty())
  49. {
  50. cout << "\nThe phrase is no more.\n";
  51. }
  52.  
  53. return 0;
  54. }
Add Comment
Please, Sign In to add comment