Question
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
string str ("nobody does like this");
7.
string key ("nobody");
8.
size_t f;
9.
f = str.rfind(key);
10.
if (f != string::npos)
11.
str.replace (f, key.length(), "everybody");
12.
cout
What is the output of this program?
1.
#include
2.
#include
3.
using namespace std;
4.
int main ()
5.
{
6.
string str ("nobody does like this");
7.
string key ("nobody");
8.
size_t f;
9.
f = str.rfind(key);
10.
if (f != string::npos)
11.
str.replace (f, key.length(), "everybody");
12.
cout
Answer: Option D
Was this answer helpful ?
rfind is used to find the characters in the string and replace is used to replace with certain characters.
Output:
$ g++ stri2.cpp
$ a.out
everbody does like this
Was this answer helpful ?
Submit Solution