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

  • SEARCH
  • Home
  • 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 168059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:23:09+00:00 2026-05-11T12:23:09+00:00

I know that cout have buffer several days ago, and when I google it,

  • 0

I know that cout have buffer several days ago, and when I google it, it is said that the buffer is some like a stack and get the output of cout and printf from right to left, then put them out(to the console or file)from top to bottem. Like this,

a = 1; b = 2; c = 3; cout<<a<<b<<c<<endl; buffer:|3|2|1|<-   (take “<-” as a poniter)  output:|3|2|<-     (output 1)         |3|<-       (output 2)         |<-         (output 3) 

Then I write a code below,

#include <iostream>  using namespace std;  int c = 6; int f()  {        c+=1;      return c;  }   int main()  {       int i = 0;       cout <<'i='<<i<<' i++='<<i++<<' i--='<<i--<<endl;       i = 0;      printf('i=%d i++=%d i--=%d\n' , i , i++ ,i-- );       cout<<f()<<' '<<f()<<' '<<f()<<endl;       c = 6;      printf('%d %d %d\n' , f() , f() ,f() );      system('pause');      return 0;  } 

Under VS2005, the output is

i=0 i++=-1 i--=0 i=0 i++=-1 i--=0 9 8 7 9 8 7 

It seems that the stack way is right~ However, I read C++ Primer Plus yesterday, and it is said that the cout work from left to right, every time return an object(cout), so ‘That’s the feature that lets you concatenate output by using insertion’. But the from left to right way can not explain cout<

Then Alnitak tell me that, ‘The << operator is really ostream& operator<<(ostream& os, int), so another way of writing this is: operator<< ( operator<< ( operator<< ( cout, a ), b ), c )’,

If the rightest argument is first evaluated, it can be some explained.

Now I’m confused about how cout’s buffer work, can somebody help me?

  • 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. 2026-05-11T12:23:10+00:00Added an answer on May 11, 2026 at 12:23 pm

    You are mixing a lot of things. To date:

    • Implementation details of cout
    • Chained calls
    • Calling conventions

    Try to read up on them separately. And don’t think about all of them in one go.

    printf(‘i=%d i++=%d i–=%d\n’ , i , i++ ,i– );

    The above line invokes undefined behavior. Read the FAQ 3.2. Note, what you observe is a side-effect of the function’s calling convention and the way parameters are passed in the stack by a particular implementation (i.e. yours). This is not guaranteed to be the same if you were working on other machines.

    I think you are confusing the order of function calls with buffering. When you have a cout statement followed by multiple insertions << you are actually invoking multiple function calls, one after the other. So, if you were to write:

    cout << 42 << 0; 

    It really means: You call,

    cout = operator<<(cout, 42) 

    and then use the return in another call to the same operator as:

    cout = operator<<(cout, 0) 

    What you have tested by the above will not tell you anything cout‘s internal representation. I suggest you take a look at the header files to know more.

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

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, you can use Settings.Settings files for web application projects.… May 12, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer You need to override the Dispose method from Form Typically… May 12, 2026 at 12:15 am
  • Editorial Team
    Editorial Team added an answer Unfortunately I have a solution myself. All you have to… May 12, 2026 at 12:15 am

Related Questions

I know cout and printf have buffer today, and it is said that the
I know all kinds of ostreams holds their own internal buffers. I have to
I am not particularly new to C/C++ but today I discovered some things that
In an Xcode project, if I use std::cout to write to the console the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.