General string and char question

I know that isdigit is used to check if char has digits. Is there a way to check if a string has a number in a similar way. Also for upper and lower cases?
isdigit is used to check if char has digits.

I think you mean ...that one or more characters in a string is a digit.....or ... if a character is a digit. Yes the isdigit() function is from the Standard C Library <cctype> and takes no notice of case. It returns non zero if the character is a digit otherwise it returns 0.
Well I have been doing a program that checks the length of a string. Also if it has a upper or lower case and finally if it has any numerical value. I already have the length correct by doing an "if" statement saying
1
2
if(pass.length()>LENGTH){return true; else return false}//In a funct.
//LENGTH is 6 and it is a "const int variable"  
. But now i need something to check for numbers and the upper or lower cases. Any ideas?

Here is snippet of the program.

I could have used chars instead of strings to make life easier but I have to use strings.

main()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int main()
{
    bool ok = true;

    // Explain program to user and request a password
    cout << "This program checks passwords to see if they are secure.";
    cout << "\nEnter a password to check: ";

    // Read user's input
    string password;
    cin >> password;

    // Check the password
    if (!isLongEnough(password))
    {
            cout << "Password must be at least six characters long." << endl;
            ok = false;exit(0);
    }
    if (!hasDigit(password))
    {
            cout << "Password must have at least one digit." << endl;
            ok = false;
    }
    if (!hasUpperAndLowerCase(password))
    {
            cout << "Password must have both lower case and upper case letters." << endl;
			
            ok = false;
    }

    if (ok) {
            cout << "The password " << password << " is OK." << endl;
    }
    return 0;        
}

you can access string suing indices


1
2
3
4
5
6
7
8
9
10
11
...
string one="hello world 1234";
unsigned int A=0,a=0;

for(unsigned int i=0; i<one.length(); i++)
{
    if(('a'<=one[i] && one[i] <='z'))
        a++;
    else if(
...
Thanks tejashs. Now would the same work with capitalism and lower cap?
Never mind it does. Thank you, it worked :)
Dang, your code is CLEAN and CLASSY! I wish all my code looked that good. Maybe I should get that "Clean Code" book.
cout << "Lol yeah"<< endl;
Topic archived. No new replies allowed.