Home » C++ Programming » Strings » Question
  1. What is the output of this program?
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
    string s ("Nobody does like Interview Mania.");
    string key ("Nobody");
    size_t f;
    f = s.rfind(key);
    if (f != string::npos)
    s.replace (f, key.length(), "Everybody");
    cout << s << endl;
    return 0;
    }
    1. Nobody
    2. Everybody
    3. Everybody does like Interview Mania.
    4. Nobody does like Interview Mania.
    5. None of these
Correct Option: C

rfind is used to find the characters in the string and replace is used to replace with certain characters.



Your comments will be displayed only after manual approval.