1. 程式人生 > >c++ 去除字串中的空格和標點符號 (remove_if 函式的用法)

c++ 去除字串中的空格和標點符號 (remove_if 函式的用法)

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()); 


注意需要包含如上兩個標頭檔案