Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我如何检查main中的布尔变量,以便do while循环遍历这三个函数?_C++_String_Vector_Project - Fatal编程技术网

C++ 我如何检查main中的布尔变量,以便do while循环遍历这三个函数?

C++ 我如何检查main中的布尔变量,以便do while循环遍历这三个函数?,c++,string,vector,project,C++,String,Vector,Project,好吧,我的问题是,我似乎找不到或想不出任何东西会进入while参数,它会检查所有三个函数,看看每个函数是否为false,请帮助!这就是我的问题 class Validate { public: Validate(string); Validate(); bool checkLength(); bool checkSpaces(); bool checkUpper(); //bool checkUpper(char); private:

好吧,我的问题是,我似乎找不到或想不出任何东西会进入while参数,它会检查所有三个函数,看看每个函数是否为false,请帮助!这就是我的问题

class Validate
{
public: 
    Validate(string);
     Validate();
    bool checkLength();
    bool checkSpaces();
    bool checkUpper();
    //bool checkUpper(char);
private:
    string password;
    static const int LEN = 5;

};
Validate::Validate()
{

}
Validate::Validate(string pass)
{
    pass = password;

}
bool Validate:: checkLength()
{
        if (password.length() < LEN)
        {
            cout << "Password is not 5 characters." << "  please try again..." << endl;
            return true;
        }
        else 
            return false;

}
bool Validate::checkSpaces()
{
    if (password.find(' ') != string::npos)
    {
        cout << "Password can not have any spaces " << endl;
        return true;
    }
    else
        return false;
}
bool Validate::checkUpper()
{

    for (int i = 0; i < password.length(); i++)
    {
        if (!isupper(password[i]))
        {
            cout << "Password must have at least one uppercase" << endl;
            return true;
        }
        else
            return false;
    }



}
类验证
{
公众:
验证(字符串);
验证();
bool checkLength();
bool-checkSpaces();
bool-checkUpper();
//bool-checkUpper(char);
私人:
字符串密码;
静态常数int LEN=5;
};
验证::验证()
{
}
验证::验证(字符串传递)
{
pass=密码;
}
bool Validate::checkLength()
{
if(password.length()cout你的问题有点不清楚,但我认为你在寻找:

 bool flag;

 do
 {
        // All your existing code is here...

        Validate c{password};

        flag = c.checkLength() || c.checkSpaces() || c.checkUpper();

 } while (flag);

您的
Validate
类的构造函数将密码作为参数,因此您必须在读取密码后构造对象,而不是在
main()

的开头构造对象。我尝试了这一点,但循环认为密码不正确。请调试器逐步执行您的代码。我在checkUpper()中至少看到一个错误方法。是的,调试器说“Validate::checkUpper”:不是所有的控制路径都返回值“@BartAlen好吧,错误消息很清楚,不是吗?检查该函数并为该函数中的每个可能路径提供一个返回值。好吧,我找到了错误,但我仍然需要do while循环的帮助
 bool flag;

 do
 {
        // All your existing code is here...

        Validate c{password};

        flag = c.checkLength() || c.checkSpaces() || c.checkUpper();

 } while (flag);