Char & int input

Hey guys can i ask how to make my code accept both int and char input?

Last edited on
Input for both isn't possible. However you can input a string, check it for validity and convert it to int later.

You may use stringstream to convert a string to int. See:

http://www.cplusplus.com/reference/sstream/istringstream/istringstream/
A variable has a type and it's value can only be valid for the specified type. So if it's type is char, then it holds a char value. An int holds an integer value. etc

However, with C++17 there is the concept of a std::variant that can hold values of different but specified type (but only one at a time).

https://en.cppreference.com/w/cpp/utility/variant

What are you trying to achieve - as that could determine how to approach this.

NB. You can, of course, have a program that contains 2 variables - one of type int and one of type char and obtain input of the right type into both in the code.
Topic archived. No new replies allowed.