#include <iostream>
/**
* Returns a new string trimming spaces from front and back
* @param str The original string
*/
std::string trim(const std::string &str)
{
std::string s(str);
while (s.size() > 0 && std::isspace(s.front()))
{
s.erase(s.begin());
}
while (s.size() > 0 && std::isspace(s.back()))
{
s.pop_back();
}
return s;
}
int main()
{
std::cout << trim(" 3 Hello World 3 \n");
if (trim("\t 3 Hello World 3 \n") == "3 Hello World 3") {
std::cout << "- trim removed line returns too!";
}
return 0;
}