String Exercises
What will the following statements output?
#include <iostream> #include <string> using namespace std; main() { // define variables S1, S2, S3, S4 string S1 = "Protagoras", S2 = "Epicurius", S3 = "Hippocrates", S4 = "Agathon"; cout << S3 << " is " << S3.size() << " years old"; cout << S1 << " is a " << S3.substr(0,5); cout << S3.substr(5,5) << " & barrel"; cout << S2.substr(3,6) << " george"; cout << S4.replace(0,3,"mara"); cout << S4.insert(0,"White Rock "); cout << S4 << " now has length of " << S4.size(); // define a new variable S5 string S5 = S2.substr(3,6) + " " + S3.substr(0,5); cout << "I saw a " << S5 << " in the " << S4; cout << "S5 has a pp at " << S5.find("pp",0); } |
|