conio.h
是一個(gè)在 Windows 編程中常用的頭文件,它提供了一些用于控制控制臺(tái)輸出的函數(shù),如 kbhit()
和 getch()
。然而,這個(gè)頭文件在 Linux 系統(tǒng)中并不存在。
如果你想在 Linux 系統(tǒng)中進(jìn)行類似的控制臺(tái)輸入輸出操作,你可以使用標(biāo)準(zhǔn)輸入輸出流(stdin
和 stdout
)以及 C++11 引入的 <iostream>
頭文件。下面是一些基本的示例:
#include <iostream>
#include <unistd.h> // 提供 sleep 函數(shù)
#include <termios.h> // 提供 termios 相關(guān)函數(shù)
int main() {
std::cout << "Press any key to continue...";
std::cin.get(); // 等待用戶輸入
std::cout << "You pressed " << std::cin.get() << '\n';
sleep(1); // 等待 1 秒
return 0;
}
#include <iostream>
#include <string>
int main() {
std::cout << "Enter a line of text: ";
std::string input;
std::getline(std::cin, input);
std::cout << "You entered: " << input << '\n';
return 0;
}
這些示例展示了如何在 Linux 系統(tǒng)中使用 C++ 進(jìn)行基本的控制臺(tái)輸入輸出操作。