char问题~!
这是书上例题的答案#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string s,result_srt;
bool has_punct;
char ch;
cout<<"Enter a string:"<<endl;
cin>>s;
for (string::size_type index=0;index!=s.size();++index)
{
ch=s[index];
if(ispunct(ch))
has_punct=true;
else
result_srt+=ch;
}
if (has_punct)
{
cout<<"Result:"<<endl<<result_srt<<endl;
}
else
{
cout<<"No punctuation character in the string?!"<<endl;
}
return 0;
}
这个是我写的
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string s,result_srt,ch;
bool has_punct;
cout<<"Enter a string:"<<endl;
cin>>s;
for (string::size_type index=0;index!=s.size();++index)
{
if(ispunct(s[index]))
has_punct=true;
else
result_srt+=s[index];
}
if (has_punct)
{
cout<<"Result:"<<endl<<result_srt<<endl;
}
else
{
cout<<"No punctuation character in the string?!"<<endl;
}
return 0;
}
想问下书上多加呢个char ch起什么作用?