我想知道是否可以检查字符串中的一个字母是否大写.其他查看方式,如果字符串中的所有字母都是大写或小写.例:
string a = "aaaaAaa";
string b = "AAAAAa";
if(??){ //Cheking if all the string is lowercase
cout << "The string a contain a uppercase letter" << endl;
}
if(??){ //Checking if all the string is uppercase
cout << "The string b contain a lowercase letter" << endl;
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
Sla*_*ica 12
你可以使用标准算法 std::all_of
if( std::all_of( str.begin(), str.end(), islower ) { // all lowercase
}
Run Code Online (Sandbox Code Playgroud)