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;
}
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;
}
Jump to PostWhite 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
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;
}
Thanks. That works perfectly :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.