1.删除字符串中的空格
2.将数分解,当3个数的情况,需要进一步进行留意
#pragma once
#include <iostream>
#include <string>
using namespace std;
class SpiltNum
{
public:
SpiltNum(void);
~SpiltNum(void);
void SpiltFun(int num);//将一个数拆分成几个数相加
void DelSpace(string inputChar);
};
void SpiltNum:: SpiltFun(int num)
{
cout<<"输入的值为:"<<endl;
for (int i=1;i<=num/2;i++)
{
cout<<num<<"="<<i<<"+"<<num-i<<endl;
}
}
void SpiltNum::DelSpace(string inputChar)
{
for (int i=0;i<inputChar.size();i++)
{
if (isspace(inputChar[i]))
{
//a[i].erase(i,i);
inputChar.erase(i,i);
i--;
cout<<"true"<<endl;
}
else
{
cout<<"false"<<endl;
}
}
//cout<<a<<endl;
cout<<inputChar<<endl;
//cout<<a.size()<<endl;
getchar();
//if (inputChar.length()==0)
//{
// cout<<"字符串为空"<<endl;
//}
//else
//{
//
// if (inputChar.length()!=0)
// {
// inputChar.erase(remove(inputChar.begin(),inputChar.end(), ' '),inputChar.end());
// cout<<inputChar<<endl;
// }
// else
// {
// cout<<"无空格"<<endl;
// }
///* for(int i=0;i<strlen(inputChar);i++)
// {
// if (" "==*(inputChar+i))
// {
// *(inputChar+i)=*(inputChar+i+1);
// }
// }
// return *inputChar;
// cout<<"0k"<<endl;*/
///// return "ok";
//}
}
void main()
{
SpiltNum mySpilt;
int num=3;
mySpilt.SpiltFun(num);
string astring="he ll ";
mySpilt.DelSpace(astring);
//getchar();
}