#include <algorithm>#include <cctype>#include <locale>
// trim from start (in place)static inline void ltrim(std::string &s) {s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {return !std::isspace(ch);}));}
// trim from end (in place)static inline void rtrim(std::string &s) {s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {return !std::isspace(ch);}).base(), s.end());}
// trim from both ends (in place)static inline void trim(std::string &s) {rtrim(s);ltrim(s);}
// trim from start (copying)static inline std::string ltrim_copy(std::string s) {ltrim(s);return s;}
// trim from end (copying)static inline std::string rtrim_copy(std::string s) {rtrim(s);return s;}
// trim from both ends (copying)static inline std::string trim_copy(std::string s) {trim(s);return s;}
#include <algorithm>#include <functional>#include <cctype>#include <locale>
// trim from start (in place)static inline void ltrim(std::string &s) {s.erase(s.begin(), std::find_if(s.begin(), s.end(),std::not1(std::ptr_fun<int, int>(std::isspace))));}
// trim from end (in place)static inline void rtrim(std::string &s) {s.erase(std::find_if(s.rbegin(), s.rend(),std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());}
// trim from both ends (in place)static inline void trim(std::string &s) {rtrim(s);ltrim(s);}
// trim from start (copying)static inline std::string ltrim_copy(std::string s) {ltrim(s);return s;}
// trim from end (copying)static inline std::string rtrim_copy(std::string s) {rtrim(s);return s;}
// trim from both ends (copying)static inline std::string trim_copy(std::string s) {trim(s);return s;}
const char* ws = " \t\n\r\f\v";
// trim from end of string (right)inline std::string& rtrim(std::string& s, const char* t = ws){s.erase(s.find_last_not_of(t) + 1);return s;}
// trim from beginning of string (left)inline std::string& ltrim(std::string& s, const char* t = ws){s.erase(0, s.find_first_not_of(t));return s;}
// trim from both ends of string (right then left)inline std::string& trim(std::string& s, const char* t = ws){return ltrim(rtrim(s, t), t);}
#include <algorithm>#include <functional>#include <string>
/*** @brief Left Trim** Trims whitespace from the left end of the provided std::string** @param[out] s The std::string to trim** @return The modified std::string&*/std::string& ltrim(std::string& s) {s.erase(s.begin(), std::find_if(s.begin(), s.end(),std::ptr_fun<int, int>(std::isgraph)));return s;}
/*** @brief Right Trim** Trims whitespace from the right end of the provided std::string** @param[out] s The std::string to trim** @return The modified std::string&*/std::string& rtrim(std::string& s) {s.erase(std::find_if(s.rbegin(), s.rend(),std::ptr_fun<int, int>(std::isgraph)).base(), s.end());return s;}
/*** @brief Trim** Trims whitespace from both ends of the provided std::string** @param[out] s The std::string to trim** @return The modified std::string&*/std::string& trim(std::string& s) {return ltrim(rtrim(s));}
#include <string>#include <cctype> // for isspaceusing namespace std;
// Left trim the given string (" hello! " --> "hello! ")string left_trim(string str) {int numStartSpaces = 0;for (int i = 0; i < str.length(); i++) {if (!isspace(str[i])) break;numStartSpaces++;}return str.substr(numStartSpaces);}
// Right trim the given string (" hello! " --> " hello!")string right_trim(string str) {int numEndSpaces = 0;for (int i = str.length() - 1; i >= 0; i--) {if (!isspace(str[i])) break;numEndSpaces++;}return str.substr(0, str.length() - numEndSpaces);}
// Left and right trim the given string (" hello! " --> "hello!")string trim(string str) {return right_trim(left_trim(str));}
void trim(std::string& s) {if (s.empty())return;
int l = 0, r = s.size() - 1;
while (l < s.size() && std::isspace(s[l++])); // l points to first non-whitespace char.while (r >= 0 && std::isspace(s[r--])); // r points to last non-whitespace char.
if (l > r)s = "";else {l--;r++;int wi = 0;while (l <= r)s[wi++] = s[l++];s.erase(wi);}return;}
std::string text = "Let me split this into words";
std::istringstream iss(text);std::vector<std::string> results((std::istream_iterator<std::string>(iss)),std::istream_iterator<std::string>());