使用像std :: find()这样的算法函数会有更好的方法吗?
std::string s = "012X012Y012";
//After erasing the numbers from beginning and end; the end result should be X012Y
size_t index = s.find_first_not_of("0123456789");
string::iterator iter_end = s.begin();
advance(iter_end, index);
s.erase(s.begin(), iter_end);
//Now std::string should be X012Y012
size_t index = s.find_last_not_of("0123456789")+1;
string::iterator iter_start = s.begin();
advance(iter_start, index);
s.erase(iter_start, s.end());
//Finally, std::string should be X012Y
Run Code Online (Sandbox Code Playgroud)