用C++的getchar函数获得字符h e l l o 分别赋给5个变量,然后输出字符串hello
时间: 2024-03-12 17:48:45 浏览: 23
可以使用以下代码实现:
```c++
#include <iostream>
using namespace std;
int main() {
char h, e, l1, l2, o;
cout << "Please input 'hello': ";
h = getchar();
e = getchar();
l1 = getchar();
l2 = getchar();
o = getchar();
cout << "The string is: " << h << e << l1 << l2 << o << endl;
return 0;
}
```
运行程序后,程序会提示用户输入 "hello",然后使用 `getchar()` 函数逐个读入字符,并赋值给相应的变量。最后将这些变量拼接起来输出即可。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)