Kat H.

asked • 05/04/21

String Trim2. Write a function stringTrim that removes the first and last characters from a given string.

Write a function stringTrim that removes the first and last characters from a given string. "chello" should become "hell".


Your function must work correctly given the code in main shown below. Examine it to decide if you should return the new value or use a reference parameter.

int main()
{
string word = "bob";
string result = stringTrim(word);
cout << result << endl;
}


Code:


#include <iostream>

#include <string>

using namespace std;

//Do not modify anything on or above the line below this

//YOUR_CODE_BELOW


//YOUR FUNCTION HERE



//YOUR_CODE_ABOVE

//Do not modify anything on or below the line above this


int main()

{

string word;

cin >> word;

string result = stringTrim(word);

cout << result << endl;


}

1 Expert Answer

By:

Patrick B. answered • 05/04/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.