invalid conversion from ‘const char*’ to ‘char’

Best Ways to Trim a string in C++ [stackoverflow]

Author posted @ 2013年2月19日 05:48 in C/C++ , 3720 阅读

1. Using boost::algorithm

#include <boost/algorithm/string.hpp>
using namespace std;
using namespace boost::algorithm;

string str1(" hello world! ");

2. Define inline function:

#include <algorithm> 
#include <functional> 
#include <cctype>
#include <locale>

// trim from start
static inline std::string <rim(std::string &s) {
        s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
        return s;

// trim from end
static inline std::string &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());
        return s;

// trim from both ends
static inline std::string &trim(std::string &s) {
        return ltrim(rtrim(s));

SEO 说:
2022年1月19日 06:57

My experience with Caldwells was really not what I expected. They suggested things that I never knew I needed for my project. Check their site to their products.

SEO 说:
2022年2月10日 01:07

This type of message always inspiring and I prefer to read quality content, so happy to find good place to many here in the post, the writing is just great, thanks for the post.

登录 *

loading captcha image...
or Ctrl+Enter