我是新手,正在學習C++。我目前正在學習cctype中的字符函數(ctype)。我無法理解爲什麼isspace(a_character)沒有返回我的cout消息 - 問題是它不會接受我的Char用戶輸入。任何幫助或轉向正確的方向將不勝感激。如果我指定「'的Char值,我可以實現我想要的響應,但是,它會破壞目的。我複製了一部分代碼。據我的理解,Whitespace沒有確切的符號?如果是這樣,是否可以輸入一個空格作爲輸入?我試過輸入:''然而,還沒有成功。再次,我將不勝感激。Isspace字符功能
#include <iostream>
#include <cctype>
#include <ctype.h>
using namespace std;
int main()
{
char c ;
char ans = 'y' || 'Y';
do {
cout << "Enter a character \n";
cin >> c;
if (isspace (c)) //Having trouble get this to actually produce a value
{
cout << "Your character " << c << "is a whitespace";
}
if (ispunct(c))
{
cout << c << " is a punctuation character\n";
}
cout << "Would you like to enter another value? \n";
cin >> ans;
} while (ans == 'Y' || ans == 'y');
return 0;
}
'char ans ='y'|| 'Y';'咦? – John3136
對於我的while循環來提示用戶他們是否想重複該程序 – Rod
''y'|| 'Y''簡單地說就是'真'。 –