In C is there a simple way to accept user input store as cin

In C++, is there a simple way to accept user input, store as cin object, and plug the input into a sizeof operator to return the size of the data type the user entered, without using any extended if-else statements? I\'m talking like, C++ 101 way to do this. I.E., you cout asking for a data type, and the program will tell you the size in bytes of an integer if the user entered int, or size in bytes of a character if they enter char. To reiterate, a simple way involving putting the input straight into the operator, not drafting a list matching all the input option with the respective sizeof operation.

Solution

#include using namespace std; int main() { int x; char y; float z; double a; cin>>x; cin>>y; cin>>z; cin>>a; cout << \"x is \" << sizeof(x) << \" bytes\"; cout << \"y is \" << sizeof(y) << \" bytes\"; cout << \"Size of float : \" << sizeof(z); cout << \"Size of double : \" << sizeof(a); return 0; }
In C++, is there a simple way to accept user input, store as cin object, and plug the input into a sizeof operator to return the size of the data type the user

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site