df 去空格

本文提供了几个使用C++进行字符串处理的方法,包括去除空字符、查找并删除指定字符等实用功能,通过具体代码实例展示了如何高效地操作字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>

#include <functional>
void main()
{
string str(" d df df ");
string::iterator new_end = remove_if(str.begin(), str.end(), bind2nd(equal_to<char>(), ' '));

str.erase(new_end, str.end());
cout << str << endl;
}

 

 

 

 

#include <iostream> #include <string>usingnamespace std; void Fun(string& str); int main() { string str(" I am a flur "); cout<<str<<endl; Fun(str); cout<<str<<endl; return0; } void Fun(string& tempStr) { string::size_type loc =0; loc = tempStr.find(''); while (loc !=string::npos) { tempStr.erase(loc,1); loc = tempStr.find('',loc); } }

 

#include <string>usingnamespace std; void Fun(string&str) { int i = str.length(); int t =0; char* temp =newchar[i +1]; for (int j =0; j < i; j++) { if (str[j] !='' ) { temp[t++] = str[j]; } } temp[t] ='\0'; str = temp; delete []temp; } void main() { string a ="he l lo"; Fun(a); cout << a << endl; }

转载于:https://www.cnblogs.com/dengyigod/articles/2574050.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值