-
isspace()
What is wrong with that code?
It executes else() but wont execute if(). It just hangs.
Code:
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char x;
for (;;)
{
cout << "Type a character: " << endl;
cin >> x;
if( isspace(x) )
{
cout << "It's a space." << endl;
}
else
{
cout << "It's not a space." << endl;
}
}
}
-
I think the problem is that formatted input ignores whitespace by default. Perhaps the simplest option is to just use cin.get() instead.
-
Yeah works for me using cin.get(x) instead.
-