How is std::iostream buffered?

后端 未结 2 837
臣服心动
臣服心动 2020-12-31 01:12

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 correspondi

2条回答
  •  心在旅途
    2020-12-31 01:45

    The answers to the immediate questions on whether and how std::istream is buffered are: yes, std::istream is buffer using a class derived from std::streambuf which defines the actual buffering and reading approach for a concrete source (or, when using an std::ostream for a destination). Whether this really does any buffering depends on this concrete class and its operation can generally not avoided.

    That said , this isn't you problem! The problem is that normally input isn't sent to standard input if a program until the newline key is hit. This is so that some line editing can be done by the terminal implementation and doesn't have to be done by every program. Unfortunately, there is no portable approach to change this. On POSIX youcan turn the standard input stream (using file descriptor 0) into non-canonical mode using tcgetattr() and tcsetattr(). I don't know how to achieve this on non-POSIX systems.

提交回复
热议问题