我在檢查輸入時遇到了一些問題。我知道那裏已經有類似的問題,但是它並沒有解決我的問題。我已經在使用其他問題的建議之一,但它不起作用。檢查輸入是否是正確的整數
#include <iostream>
#include <stdio.h>
#include <ctype.h>
int main()
{
int a;
printf("Please type in your number: ");
scanf_s("%d", &a);
if(isdigit(a))
{
printf("True.");
}
else
{
printf("False.");
}
std::cin.get();
std::cin.get();
return 0;
}
我不知道我做錯了,但我的輸出始終是「假」當我在一個號碼類型。當我輸入一個字母時,編譯器有錯誤。
你爲什麼要標記這個C? – GManNickG 2010-11-08 20:49:32
[我如何在C++中驗證用戶輸入爲double?](http://stackoverflow.com/questions/3273993/how-do-i-validate-user-input-as-a-double-in -c)和其他許多... – 2010-11-08 20:54:38
當你嘗試'48'時會發生什麼? :-) – pmg 2010-11-08 21:03:24