我有一個有符號整數變量 當我這樣做在main中,它也給我「錯誤」的整數值以及。isdigit問題與cin
int main(){
unsigned int a;
while(cin>>a){
if(!isdigit(a)){
cout<<"Error"<<endl;
}
}
}
[編輯]: 感謝所有的答覆,我明白了這個問題。現在,我該如何檢查cin是否只讀取整數而不是字母或任何其他字符。有沒有在c + +中的任何功能。由於
可能是因爲你的字符r正在簽署擴展。請參閱http://stackoverflow.com/questions/8083083/how-do-you-cope-with-signed-char-int-issues-with-standard-library – Mordachai