阅读量:114
conio.h 是一个在 Windows 编程中常用的头文件,它提供了一些用于控制控制台输出的函数,如 kbhit() 和 getch()。然而,这个头文件在 Linux 系统中并不存在。
如果你想在 Linux 系统中进行类似的控制台输入输出操作,你可以使用标准输入输出流(stdin 和 stdout)以及 C++11 引入的 头文件。下面是一些基本的示例:
- 读取单个字符:
#include
#include // 提供 sleep 函数
#include // 提供 termios 相关函数
int main() {
std::cout << "Press any key to continue...";
std::cin.get(); // 等待用户输入
std::cout << "You pressed " << std class="hljs-built_in">get() << '\n';
sleep(1); // 等待 1 秒
return 0;
}
- 读取一行文本:
#include
#include
int main() {
std::cout << "Enter a line of text: ";
std::string input;
std::getline(std::cin, input);
std::cout << "You entered: " << input << ;
return 0;
}
这些示例展示了如何在 Linux 系统中使用 C++ 进行基本的控制台输入输出操作。