前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >c++ 去除字符串中的空格和标点符号 (remove_if 函数的用法)

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

作者头像
用户7886150
修改2021-02-09 11:21:37
3.1K0
修改2021-02-09 11:21:37
举报
文章被收录于专栏:bit哲学院

参考链接: C++ isspace()

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

注意需要包含如上两个头文件

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档