0
How does one force a C++ program only to accept numbers(example: "12#"or"7&5"or"@12"or"a12"or"a"or"A"or"#" is invalid) ?
C++
5 Respuestas
+ 2
get the string creat a function, send string to it, check it with for-loop if any character is out of ‘1’ to ‘9’ return false break, after loop return true... thats it
+ 2
A quick method:
std::string s;
int c;
while (1) {
c = getchar();
if (c == 13 || c == 10)
break;
if (c > 47 && c < 58)
s.push_back(c);
}
You'll still see typing letters, but the string, s, will only have numbers.
0
Accept numbers from where? User input? Call to a function?