c++用for循环遍历整个字符串。发现不是.或数字

“用for循环遍历整个字符串。发现不是.或数字”用代码应该怎么表达呢?

第1个回答  2007-05-24
用得是 c++里得字符串, 没有用c风格得字符串!

#include <iostream>
#include <string>
#include <cctype>

using namespace std;

int main()
{
bool flag=false;
string str;
getline(cin,str);
for (size_t i=0;i!=str.size();++i)
{
if ( isdigit(str[i]) || str[i]=='.')
flag=true;
}
if (flag)
cout<<"含有数字和.!"<<endl;
else
cout<<"不含有数字和.!"<<endl;
}本回答被提问者采纳
第2个回答  2019-03-22
用得是
c++里得字符串,
没有用c风格得字符串!
#include
#include
#include
using
namespace
std;
int
main()
{
bool
flag=false;
string
str;
getline(cin,str);
for
(size_t
i=0;i!=str.size();++i)
{
if
(
isdigit(str[i])
||
str[i]=='.')
flag=true;
}
if
(flag)
cout<<"含有数字和.!"<
评论
0
0
加载更多
第3个回答  2007-05-24
for(i=0;i<strlen(thestr);i++)
if(!(thestr[i]=='.'||(thestr[i]>='0'&&thestr[i]<='9')))
{
.....
}
明白?
第4个回答  2007-05-24
好象是英文状态下的此符号

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网