请详细解释一下这段代码的实现过程

来源:百度知道 编辑:UC知道 时间:2024/09/19 16:14:30
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main()
{
int all_digital(const string &s,int i, int j);
string sen;
cout<<"Please input a sentense.\n";
getline(cin,sen);
cout<<"The original sentense is :\n";
cout<<sen<<endl;

for(size_t m=0,t=0;m<sen.length();)
{
m=sen.find_first_not_of(" \t",m);??????
t= sen.find_first_of(' ',m);??????
if( t == string::npos) t= sen.length();?????
if( all_digital(sen, m, t) )
{
for(; m<t; m++)
sen[m]='x';
}
m=t;
}
cout<<sen<<endl;
return 0;
}
这段代码是用来实现把一串字符串中不和字母组合的数字转换成x
如:22 ds22 22ss
xx ds22 22ss

但小弟对其中的实现原理不是很懂,尤其是加了问号的那几行,还请高手详细讲解一下哈!!!!!!!!!!!

m=sen.find_first_not_of(" \t",m);??????
t= sen.find_first_of(' ',m);??????
if( t == string::npos) t= sen.length();?????

find_first_not_of方法判断字符串是否不是以某个字符开头
finde_first_of方法判断字符串是否以某个字符开头
npos是string类的一个成员,初始值为-1
length方法是计算字符串的字符数的函数
这3个方法和1个成员变量都是在string类中定义的

具体用法可以查询下MSDN