Note that there are some explanatory texts on larger screens.

plurals
  1. POHow is std::iostream buffered?
    primarykey
    data
    text
    <h1>General use case</h1> <p>I am trying to implement a basic shell.</p> <h1>Description</h1> <p>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'.</p> <p>An input example would look like this (where <code>&gt;</code> is the shell prompt):</p> <pre><code>&gt; 111-222-333-444a Ok, '111-222-333-444' entered </code></pre> <h2>Why do I want inline delimiter instead of 'new-line' delimiter?</h2> <p>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).</p> <p>Because I would like to listen to keyboard event such as 'tabulation' to automaticly complete the current command (implementing auto-completion feature).</p> <h2>What I have so far</h2> <p>Up to now, my code looks like this:</p> <pre><code>bool done = false; char c; while (!done &amp;&amp; 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; } } </code></pre> <p>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.</p> <h2>What is the question?</h2> <p>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?</p> <p>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 library that implement all this stuff.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload