关于网友提出的“ C++菜鸟救教”问题疑问,本网通过在网上对“ C++菜鸟救教”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: C++菜鸟救教
描述: 第九行if (has_punct)是什么意思,是false还是true
#include
#include
#include
using namespace std;
int main()
{
string s,all_str;
char ch;
bool has_punct=false;
cout<<"Enter a string:"<<>
getline (cin,s);
for (string::size_type index=0;index<>
{
ch=s[index];
if (ispunct(ch))
has_punct=true;
else
all_str=all_str+ch;
}
if (has_punct)
cout<<"Result:"<<><><>
else
{
cout<<"The string is wrong!"<<>
return -1;
}
return 0;
}
解决方案1:
抱谦是我没看仔细,
ispunct这个是string里定义的函数,has_punct只是个变量啊...你自己定义的普通的局部变量
解决方案2:
先判断里面有无标点符号。更新has_punct
那has_punct也是CCTYPE里面的函数吗
has_punct不是函数啊。只是个bool变量
bool has_punct=false;解决方案3: 如果输入里面包含标点符号就是 true,否则就是 false
以上介绍了“ C++菜鸟救教”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/3709370.html