-3

I am relatively new to programming, and I can only really understand C++. I have recently started working on a project that requires the user to input something that will allow them to make a selection. I can't figure out how to make it possible for the user to input a string or a char but get the same result. I know that this would require that I assign the variable that the user inputs (for example 'a') two data types, but how do I do that? I've tried using "string/char a;" but that doesn't work.

Could someone please help me with multi-data-type variables?

Thanks

4

2 回答 2

1

字符串类型适用于所有用户输入。由于它对您“不起作用”,如果您不向我们展示您的尝试,我们将无法进一步帮助您。

于 2013-07-20T22:16:15.037 回答
1

如果用户是从 I/O 进行输入的人,那么您可以决定是否将输入视为字符串或字符。收到输入后,您应该知道要使用它做什么。您还可以将输入数据存储在数组、向量或列表中。原始数据类型可以做很多事情,只需了解程序的目的和功能。

于 2013-07-20T22:31:32.987 回答