KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
General use case I am trying to implement a basic shell. Description I need to read user input until some delimiters are pressed so a corresponding action can be performed. Those delimiter could be a single 'a', a single 'b' or a single 'c'. An input example would look like this (where > is the shell prompt): > 111-222-333-444a Ok, '111-222-333-444' entered Why do I want inline delimiter instead of 'new-line' delimiter? Because I would like to listen to keyboard event such as 'up-arrow' to erase the current command and print the last command (implementing a history feature). Because I would like to listen to keyboard event such as 'tabulation' to automaticly complete the current command (implementing auto-completion feature). What I have so far Up to now, my code looks like this: bool done = false; char c; while (!done && std::cin.get(c)) { switch (c) { case 'a': // Do something corresponding to 'a' done = true; break; case 'b': // Do something corresponding to 'b' done = true; break; case 'c': // Do something corresponding to 'c' done = true; break; default: // buffer input until a delimiter is pressed break; } } However, the loop seem to be executed only after the 'new-line' key have been pressed. This behaviour kill the interactive essence of the user input. What is the question? I know std::ostream is buffered so content is not write to disk until some event occured but what about std::istream. Is it buffered? If yes, how is it and what are my option to bypass this behaviour? Also, I've tagged this question as 'homework' because, event if it is not a school exercice, it is an exercise I am trying to do by myself and I do not want to only pick a libra
Tags (comma-separated)
Save Edits
Cancel