C++中提供了自动删除空格和标点符号的函数,使用如下:
#include <ctype.h>
#include <algorithm>
str_testing.erase(
remove_if ( str_testing.begin(), str_testing.end(), static_cast<int(*)(int)>(&ispunct) ),
str_testing.end());
str_testing.erase(
remove_if ( str_testing.begin(), str_testing.end(), static_cast<int(*)(int)>(&isspace) ),
str_testing.end());
注意需要包含如上两个头文件
更多推荐
c++ 去除字符串中的空格和标点符号 (remove_if 函数的用法)
发布评论