0
#include <cctype> // Character testing and conversion
using std::cin;
using std::cout;
using std::endl;
int main() {
char letter = 0; // Store input in here
cout << endl
<< "Enter a letter: "; // Prompt for the input
cin >> letter; // then read a character
if(std::isupper(letter)) { // Test for uppercase letter
cout << "You entered a capital letter."
<< endl;
cout << "Converting to lowercase we get "
<< static_cast<char>(std::tolower(letter)) << endl;
return 0;
}
if(std::islower(letter)) { // Test for lowercase letter
cout << "You entered a small letter."
<< endl;
cout << "Converting to uppercase we get "
<< static_cast<char>(std::toupper(letter)) << endl;
return 0;
}
cout << "You did not enter a letter." << endl;
return 0;
}
在这个例子中,使用'std ::'if(std::isupper(letter)) {
而不使用'std ::'if(isupper(letter)) {
?有什么区别?这两个区别?
我都尝试和他们返回相同的结果,所以我不知道什么是使用的效益“的std ::”
没有std ::,你会从当前范围调用一个名为isupper()的函数,如果没有,从全局命名空间(:: isupper())。编写std :: isupper()引用命名空间std中的函数名称isupper()。 – namezero
@namezero不,如果你是愚蠢的,并使用'使用命名空间标准;' –
一些细微的差异。 'std :: isupper()'[here](http://www.cplusplus.com/reference/locale/isupper/)和'isupper()'[here](http://www.cplusplus.com/reference/cctype/isupper /)。 – Jamal