C++初学者救教

C++菜鸟救教第九行if (has_punct)是什么意思,是false还是true#include iostream#include string#inclu

C++菜鸟救教
第九行if (has_punct)是什么意思,是false还是true


#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string s,all_str;
char ch;
bool has_punct=false;
cout<<"Enter a string:"<<endl;
getline (cin,s);
for (string::size_type index=0;index<s.size();++index)
{
ch=s[index];
if (ispunct(ch))
has_punct=true;
else
all_str=all_str+ch;
}
if (has_punct)
cout<<"Result:"<<endl<<all_str<<endl;
else
{
cout<<"The string is wrong!"<<endl;
return -1;
}
return 0;
}
[解决办法]
如果输入里面包含标点符号就是 true,否则就是 false
[解决办法]

引用:
Quote: 引用:

先判断里面有无标点符号。更新has_punct

那has_punct也是CCTYPE里面的函数吗

has_punct不是函数啊。只是个bool变量
bool?has_punct=false;
[解决办法]
引用:
Quote: 引用:

Quote: 引用:

那has_punct也是CCTYPE里面的函数吗

是string里的函数...


那一开始定义的has_punct=false是没有用的咯?

抱谦是我没看仔细,
ispunct这个是string里定义的函数,has_punct只是个变量啊...你自己定义的普通的局部变量