Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7751715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:37:08+00:00 2026-06-01T11:37:08+00:00

General use case I am trying to implement a basic shell. Description I need

  • 0

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 library that implement all this stuff.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:37:10+00:00Added an answer on June 1, 2026 at 11:37 am

    If you are on a POSIX operating system, you can set the terminal to be unbuffered using the functions and structures declared in termios.h. Basically you need to disable canonical input, and setup the terminal for non-canonical mode. These are some links that can help you with understanding the difference between the two terminal modes:

    1. Noncanonical Input (from the libc manual)

      In non-canonical input mode, the special editing characters such as ERASE and KILL are ignored. The system facilities for the user to edit input are disabled in noncanonical mode, so that all input characters (unless they are special for signal or flow-control purposes) are passed to the application program exactly as typed. It is up to the application program to give the user ways to edit the input, if appropriate.

    2. Canonical vs. non-canonical terminal input

      For canonical input – think shell; actually, think good old-fashioned Bourne shell, since Bash and relatives have command-line editing. You type a line of input; if you make a mistake, you use the erase character (default is backspace, usually; sometimes DEL) to erase the previous character … For non-canonical input – think vi or vim or … you press a character, and it is immediately available to the program. You aren’t held up until you hit return.

    3. Description of Terminal Interface

      This chapter describes a general terminal interface that is provided to control asynchronous communications ports. It is implementation-dependent whether it supports network connections or synchronous ports or both.

    In essence though, the issue you’re encountering is not with the C++ iostream interface itself, but rather has to-do with how the controlling terminal that the C++ iostream interface is reading from has been setup. Thus taking advantage of unbuffered I/O is going to be a platform-dependent operation, and will differ dependending on whether you’re using Windows, or an actual POSIX-compliant platform (this includes POSIX-environments for Windows such as Cygwin).

    If you find that messing around with the terminal settings is too much of a problem, you can also look into a cross-platform curses programming library such as PDCurses that will abstract most of the complexities of the underlying terminal types.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still learning to use MVVM and Prism and have some general questions:
I must really be missing something obvious, but I'm having trouble with general use
In general we use biometrics in computer applications say for authentication. Lets get 2
I wonder the general rule to use regular expression in if clause in bash?
I have a specific question, that could use a general answer... When building Multi-Tier
General approach in GWT is to use Panels and then apply custom CSS themes
I have a very general question regarding the use of LINQ vs SQL to
I understand how to use REST for doing general entity interactions - using urls
In general, If I have a choice when developing a web site to use
What is the correct type to use in Qt development (or C++ in general)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.