【发布时间】:2016-08-28 08:12:41
【问题描述】:
如何通过将字符串传递给布尔函数来让 tis 工作?我需要让用户输入一系列字符串,并且在每次输入之后,程序应该根据字符串是否符合给定条件给出反馈。该字符串应包含“1101”的子字符串,不包含任何字母。感谢您的所有帮助
#include <iostream>
#include <cstring> // for strstr
#include <string>
#include <cctype>
using namespace std;
bool stringCompare(char*y);
string str2;
int main ()
{
string str1, str2;
str1= "1101";
do
{
cout << "Please enter your string: " << endl;
cin >> str2;
while((stringCompare(str2)) == true)
{
if(strstr(str2.c_str(),str1.c_str())) // Primary string search function
{
cout << "ACCEPTED " << endl;
}
else
cout << "NOT ACCEPTED " << endl;
}
} while (2 > 1);
return 0;
}
bool stringCompare(char*y)
{
for(int a = 0; a < strlen(str2); a++)
{
if (!isdigit(str2[a]))
return false;
}
return true;
}
【问题讨论】:
-
c++,抱歉
标签: c++ string function boolean