题目:
代码:
#include<iostream>
using namespace std;
void test(string str,string a[],int &count){
for(int i = 0;i<str.length();i++){
if( (str[i]>='A'&&str[i]<='Z') || (str[i]>='a'&&str[i]<='z') ){
int j=i+1;
while(j<str.length()&&str[j]!=' ')
j++;
a[count]=str.substr(i,j-i);
count++;
i=j;
}
}
}
int main(){
string str="that is a question";
string a[100];
int count=0;
test(str,a,count);
for (int i = 0 ;i<count;i++)
cout<<a[i]<<"\t"<<a[i].length()<<endl;
return 0;
}
效果: