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 7850223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:47:09+00:00 2026-06-02T18:47:09+00:00

Why do we need a buffer when we get input from the user? For

  • 0

Why do we need a buffer when we get input from the user?

For example:

chat arr[10];
cin>>arr;
// or
cin.get(arr,10);

I read that there is a temporary variable called buffer that stores the input that the user typed. So:

  1. Does the compiler use the buffer just in case of char array? If the answer is “no” then when does it get used?

  2. What is the reason that the compiler uses buffer in my example above?

  3. If the buffer in my example above is an array, how the compiler choose its size?

  • 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-02T18:47:10+00:00Added an answer on June 2, 2026 at 6:47 pm

    There are several intermediate buffers involved, for various reasons:

    1. The OS has an internal buffer. This depends somewhat on the input
      device: the physical reads from a disk are by sector, so a buffer which
      is a multiple of the sector size must be used; keyboard input is
      normally buffered up until a newline character, to allow a limited
      degree of editing (backspace, etc.); and so on. This is mostly
      transparent to the application, although it does mean that even when
      reading just a single character, the read won’t return until the user
      inputs a newline.

    2. The streambuf used by the istream has a buffer. This is done to
      reduce the number of requests to the OS. The size of this buffer will
      generally depend on the type of streambuf; a filebuf will normally be
      optimized for the platform file IO—big enough to effectively
      reduce requests, but not so big as to induce paging. On some systems,
      with some types of files, it’s possible that the filebuf replaces its
      buffer with a memory mapping of the file.

    The streambuf has functions which allow modifying its buffer management
    somewhat. It’s very rare that they should be used, however; the authors
    of the library have generally done a good enough job that you can’t
    easily improve on it.

    With regards to the >> operator: this buffering all occurs at a lower
    level. The >> operator (and indeed all input from an istream)
    forwards requests for individual characters, or arrays of characters, to
    the streambuf. This decoupling of actual input of characters from the
    parsing of them is fundamental to the design of istream: istream
    takes care of the parsing only; it contains a pointer to a streambuf
    which takes care of the actual input. (Some of the parsing functions
    may also contain buffers. For example, >> of an int may collect the
    sequence of digits in a buffer before starting actual conversion.)

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

Sidebar

Related Questions

Is there any need to use a custom buffer to either read or write
I need to read a massive amount of data into a buffer (about 20gig).
I need to recv() data from a socket and store it into a buffer,
Our app uses the remoteIO (audio-unit) to get audio input from mic, and DSP
I need to use the tcp socket connection to get the data from a
I have an OutputStream that I needed to read from, and so I used
Iam learning assembly and I found out how to get user input with mov
I have function in C that reads byte by byte from a given buffer
I need a java method that will read command prompt output and store it
I need to get a range (or whole range) of current buffer, run program

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.