0

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;
}

Edited by christinetom

2
Contributors
2
Replies
13
Views
3 Years
Discussion Span
Last Post by christinetom
1

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;
}

Edited by Ancient Dragon

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.