CJCoding With Joseph
15free / daySign inCreate account

Trim Spaces From Both Ends

Write the function string trim(const string& text) so it returns text with every space and tab removed from the START and the END only. Spaces inside the text stay where they are, and a string that is nothing but spaces becomes the empty string.

find_first_not_of(" \t") gives the index of the first real character (or string::npos when there is none) and find_last_not_of(" \t") the index of the last one; erase can then cut from the front and from the back.

The hidden driver reads every line of input with getline and prints each trimmed result between square brackets on its own line, so for the three lines    Red Kite  , a tab-wrapped Paper Boat and No Change it prints the output shown in Expected Output.

Do NOT write a main function.

Expected Output:

[Red Kite]
[Paper Boat]
[No Change]

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Functions
📥 Auto-Input:
Red Kite \n\tPaper Boat\t\nNo Change\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.