删除字符串中各单词间多余空格
编程实现删除字符串中各单词间多余空格,只保留一个空格。如果字首字符中有连续空格,应完全删除;如果非字母字符前后有空格应该将空格完全删除;如果末尾是一连续空格也应将其删除。
如:输入字符串“ I ’ m a student ! “,引号除外,输出结果为:“I’m a student!”,引号除外。
实现代码如下:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
string delspace(string st)//实现删除字符串中多余空格的函数
{
if(st[0]==' ')//实现连续首字符空格的删除
{