97.3k views
19 votes
Can we use a data type as a condition in C++?

For example, if a user enters a number in a string input user prompt, it executes a certain set of instructions(code). Because when I enter a number instead of a character in the terminal, it skips all cin inputs and keeps printing cout until the end of the code.

User TunaMaxx
by
5.6k points

1 Answer

9 votes
No you can’t use a data type as a condition but you can use function overloading or templates to attempt to bypass this.
User Valera Maniuk
by
4.3k points