Using C++. What am I missing???
# include # include using namespace std: int main () { string secondVerse = “Banana -fana fo -f(Name)!”: string username = ” Katie”: username. Erase (username = “(Name)”: secondverse = secondverse .replace(secondVerse. Find (replaceString), replaceString. Length(),” “): char lastchar = secondVerse.[secondVerse.length() -1): secondVerse = secondVerse.substr (theta, secondVerse.length ()-1): secondVerse = secondVerse + username + lastChar: cout
Expert Answer
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
string secondVerse = “Banana-fana fo-f(Name)!!!”;
string userName = “Walter”;
userName.erase(userName.begin());
string replaceString = “(Name)”;
int idx = secondVerse.find(“!”); //taking the index of where ‘!’ begins
string symbols = secondVerse.substr(idx, secondVerse.length()-1); //storing the ‘!’ from begin till end
secondVerse = secondVerse.replace(secondVerse.find(replaceString), replaceString.length(), “”);
idx = secondVerse.find(“!”); //again finding index of ‘!’ in updated secondVerse
secondVerse = secondVerse.substr(0, secondVerse.length()-(secondVerse.length()-idx)); //updating secondVerse till it found ‘!’
secondVerse = secondVerse + userName + symbols;
cout << secondVerse << endl;
return 0;
}