您的位置:首页 > 编程语言 > C语言/C++

c++ 去除字符串中的空格和标点符号 (remove_if 函数的用法)

2016-03-07 04:23 447 查看
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());


注意需要包含如上两个头文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: