ninja01 wrote: |
---|
Do you know any information about the library like where it comes from and why it is not standardized. |
I don't know much about the history except that some older compiler, Like Boorland C++, came with this header.
I think it was never standardized because the capabilities varied a lot between different machines and it's not even sure the standard input/output streams are connected to anything that the user can interact with directly. You can easily run your program so that input and/or output is instead connected to files.
Imagine I had the following program.
1 2 3 4 5 6 7 8
|
#include <iostream>
int main()
{
int x;
std::cin >> x;
std::cout << (2 * x) << "\n";
}
|
On Linux, if the executable file is named "double" and I had a file named "input" containing only the content "24" and then I ran the program as
./double < input > output |
then the input would get read from the "input" file and the output "48" would get stored in a file named "output". I would not see any output or get the chance to input anything. I believe something similar should work on Windows too.
Historically the standard library has been relatively small and a lot of the functionality has been left to system libraries or third-party libraries to provide. Nowadays more and more things get standardized, they even tried to put graphics into the standard library at one point, so if console applications had still been the norm I wouldn't have been too surprised if they had actually standardized something like this. But now I don't think it's going to happen.
Is there a standard library that provide the same functions as:
kbhit() and getch()? |
There are "curses" libraries that you can use. On Linux and other unix-like systems it's common to use ncurses. On Windows I think you can use pdcurses. It should be possible to write code that is compatible with both ncurses and pdcurses. There is a getch() function. I don't think there is a kbhit() function but you can accomplish the same thing using other functions.