#include <iostream>
using namespace std;
//删除字符串右边的全部空格
char *my_trim( char *str )
{
if (NULL == str)
{
throw;
}
char *const address = str;
const int ONE_ELEMENT = 1;
const char NULL_TERMINATED = '\0';
while (NULL_TERMINATED != *str)
{
++str;
}
while (address != str && isspace( *(str - ONE_ELEMENT) ))
{
--str;
}
*str = NULL_TERMINATED;
str = address;
return str;
}
int main(int argc,char*argv[])
{
char buf[] = "ok2002.com ";
cout << strlen( buf ) << endl;
my_trim( buf );
cout << strlen( buf ) << endl;
system( "PAUSE" );
return EXIT_SUCCESS;
}
/*----
24
10
请按任意键继续. . .
-----------------------*/删除字符串右边的全部空格
最新推荐文章于 2024-12-25 10:55:12 发布
本文详细介绍了如何使用C++编写一个函数来删除字符串右边的全部空格,通过代码实例展示了实现过程,并进行了效果验证。
3508

被折叠的 条评论
为什么被折叠?



