I want to create an interactive console application that allows you to enter a command in a loop. For example, the user types โsearchโ and the program find some data and print it on the screen. Then the program waits for the next command (which may be a search, exit, or other). For the convenience of users, I want my program to support the history of commands (for example, in the terminal, by pressing the up and down arrows on the keyboard). But I canโt understand how to do this because I donโt know how to print text that can be read further scanf, std :: getline, std :: cin, etc. Therefore, the code std::cin << "hello"; not compiled (no match for 'operator <in' std :: cin <"hello"). Function fprintf(stdin, "hello"); nothing prints, and scanf cannot read this printed message. Obviously, std::getline(std::cin, str); and scanf("%s", s); and gets(s) etc. Cannot read text that was issued by printf or std::out . So the question is: how can I print text on the console, which will also be in stdin ( std::cin )? Or maybe a more elegant way to organize team history?
PS I also thought about simulating a button click to print the text I need, but I hope the best way to make a history of commands
PPS I use Linux and C ++
source share