How to determine if a character is whitespace in C++

1 Answer

0 votes
#include <iostream>

using namespace std;

int main()
{
	
	char ch = 'a';
	if (isspace(ch))
		cout << "yes" << endl;
	else
		cout << "no" << endl;

	ch = ' ';
	if (isspace(ch))
		cout << "yes" << endl;
	else
		cout << "no" << endl;

	ch = '\n';
	if (isspace(ch))
		cout << "yes" << endl;
	else
		cout << "no" << endl;

	ch = '\t';
	if (isspace(ch))
		cout << "yes" << endl;
	else
		cout << "no" << endl;
	
	return 0;
}


/*
run:

no
yes
yes
yes

*/

 



answered Dec 7, 2016 by avibootz

Related questions

1 answer 205 views
1 answer 196 views
1 answer 247 views
1 answer 222 views
1 answer 186 views
1 answer 214 views
2 answers 219 views
...