devc++怎么输入两行字符
时间: 2024-04-06 07:26:57 浏览: 30
在DevC++中,你可以使用`cin`来输入字符。如果你想输入两行字符,可以按照以下步骤进行操作:
1. 首先,在程序中包含`iostream`头文件,以便使用输入输出流。
```cpp
#include <iostream>
```
2. 然后,在程序的适当位置声明两个字符串变量,用于存储输入的两行字符。
```cpp
std::string line1, line2;
```
3. 接下来,使用`cin`分别输入两行字符,并将其存储到相应的变量中。
```cpp
std::cout << "请输入第一行字符:" << std::endl;
std::getline(std::cin, line1);
std::cout << "请输入第二行字符:" << std::endl;
std::getline(std::cin, line2);
```
完整的示例代码如下所示:
```cpp
#include <iostream>
#include <string>
int main() {
std::string line1, line2;
std::cout << "请输入第一行字符:" << std::endl;
std::getline(std::cin, line1);
std::cout << "请输入第二行字符:" << std::endl;
std::getline(std::cin, line2);
std::cout << "第一行字符为:" << line1 << std::endl;
std::cout << "第二行字符为:" << line2 << std::endl;
return 0;
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)