0
How can i give space character as input in following attached code??? HOW CAN I CHECK c is space using isspace(c) function????
2 Antworten
0
$|<|>_@&
But you can get a line with spaces or single space in input by below methods↓
1)
cin.getline(char_array_name,size);
To use this method you would change your line
char c{} to char c[1];
And change the cin to cin.getline(c,1);
2)
getline(cin,string_name);
To use this method you would change your code like this ↓
int main(int argc, char *argv[])
{
string d;
cout<<"Enter a character, we will evaluate what type it is?: ";
getline(cin,d);
cout<<"==================="<<endl<<endl;
bool yes{false};
char c=d[0];
cout<<boolalpha;
yes = isalpha(c);
cout<<"Is Letter: "<<yes<<endl;
............
...........
0
You can achieve what Mohan 333 has shown by simply using the std::istream::get() method on the 'cin' object, which takes a single character as input. So instead of
`cin >> c`
do
`cin.get(c);` or `c = cin.get();`
And your code will work for any character
std::istream::get: https://www.cplusplus.com/reference/istream/istream/get/