Introduction To Object-Oriented Programming COMP2011: String Class
Introduction To Object-Oriented Programming COMP2011: String Class
Object-Oriented Programming
// index: 0123456789012345678901234567890123456789
string s = ”The rain in Spain stays mainly in the plain.”;
string s1 = s.substr(1, 2);
string s2 = s.substr(9, 8);
string s3 = s1 + ” is ” + s2;
cout s3 endl; // Output: he is in Spain
int main( )
{
//index: 01234567890123456789012345678901234567890123
string s("The rain in Spain stays mainly in the plain.");
cout s.length() endl;
int main( ) {
string s1("et"); // substring to be replaced
string s2("ad"); // replacing string
const int num words = 5;
string word[num words] = { "met", "deet", "pets", "eta", "set" };
cout "Before replacement" endl; print words(word, num words);