Hi everybody.. Hope you're all well.

I'm having a problem. How can I test for white space characters in c++ ?

If I do the below it doesn't seem to work.

char char1;

// iterating through a file

if (char1 = ' ')
{
cout << "WHITE SPACE" << endl;
}

White space includes space, line feed, and tab characters. So testing for just space isn't right. And line 5 uses the assignment operator = instead of the boolean operator ==.

The easiest way to test for white space is to use the standard macro isspace()

char char1;

// iterating through a file

if ( issapce(char1) )
{
cout << "WHITE SPACE" << endl;
}