+ 1
In c++ how to declare variable of a type which can hold either integer or character?
Depending upon users input..
3 Respostas
+ 5
The std::variant type is perfect for such a case. It can hold any one of the types you pass as type paramters
https://en.cppreference.com/w/cpp/utility/variant
Example:
```
std::variant<int, char> v;
v = 10;
// 'v' now holds int
v = 'a';
// 'v' now holds char
```
+ 1
You can either use unions or a class with a constructor for int and one for char
+ 1
Maybe you could string input and then try to parse to integer...