Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING C++...no loops. Expanding abbreviations. (1)Use getline() to get a line of

ID: 3663964 • Letter: U

Question

USING C++...no loops. Expanding abbreviations.

(1)Use getline() to get a line of user input into a string. Output the line. Ex:

Note: If an abbreviation appears twice, only the first instance gets expanded.

Support these abbreviations:

BFF -- best friend forever

IDK -- I don't know

JK -- just kidding

TMI -- too much information

TTYL -- talk to you later

----------------------------------------------------

What I have so far:

#include
#include
using namespace std;

int main()
{
string myLine = " ";
cout << "Enter text: " << endl;
getline (cin, myLine);
cout << endl;
cout << "You entered: " << myLine << endl;

-------------------------------For the next part, I know that I have to use If statements and .find/.replace(). How do I solve this problem? This is what I have so far (I know there's a few mistakes regarding the index, but I don't know how to fix it:

for (int i = 0; i < myLine.size(); i++)
{
if (myLinet.find("BFF")!= string::npos)
{ myLine.replace(i,3, "best friend forever");}

else if (myLine.find("IDK")!= string::npos)
{ myLine.replace(i,3, "I don't know");}


else if (myLine.find("JK")!= string::npos)
{myLine.replace(i,2, "just kidding");}


else if (myLine.find("TMI")!= string::npos)
{ myLine.replace(i,3, "too much information");}
else if (myLine.find("TTYL")!= string::npos)
{myLine.replace(i,4, "talk to you later");}
}
cout << "Expanded: " << myLine << endl;
return 0;
}

When I compile this, it doesn't show the expanded part. I want to now where I made the mistake.

Explanation / Answer

In case of find funcion , you just use ,