0

if i want to check that wether the entered character is char type or int type,how can i do that?

4
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by Narue
0

how can i check that wether the entered character is char type of int type?

0

I would read the input in as a string, then loop through each charcter in the string and check whats its value is using some boolean values to make note of things.

cctype header has some nice functions such as isalpha and is digit that will allow you to accomplish this task reasonable simply.

here is a simple example of what i mean
[edit]
[snipped reason= multiple posting, even after solution provided]I'm un willing to provide a code example to such a rude poster[/snipped]

DO NOT MULTIPLE POST!
[/edit]

Chris

-1

how can i check wether the entered character is char type or int type?

Votes + Comments
3* same thread! Unacceptable
0

The entered character is always of a char type. Presumably what you want is to see if that char represents a digit:

#include <cctype>
#include <iostream>

int main()
{
  char ch;

  while ( std::cin.get ( ch ) )
    std::cout<< std::boolalpha << (bool)std::isdigit ( ch ) <<'\n';
}
This topic has been dead for over six months. 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.