The below code works for every character I type in except for £
or ¬
.
Why do I get a "debug assertion fail"?
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main() {
string input;
while (1) {
cout << "Input number: ";
getline(cin, input);
if (!isdigit(input[0]))
cout << "not a digit\n";
}
}
The Microsoft docs say:
(I'm guessing Microsoft because of the comment about an "error window", but docs for other implementations place the same limit on argument values.)
EDIT: as Deduplicator observed, the error probably arises from default
char
being signed on this platform, so that you are passing negative values (different fromEOF
).std::string
useschar
, not wide characters, so my original conclusion cannot be correct.The microsoft docs say:
And they also say:
So
char
is per defaultsigned
, which means as those two characters are not ASCII they are negative in your ANSI charset, and thus you get the assertion.