C++ Accelerated Questions Chapter 0.

This is a discussion on C++ Accelerated Questions Chapter 0. within the C++ Programming forums, part of the General Programming Boards category; This could be a stupid question and already answered before but what exactly do you mean by flushing the stream?...

  1. #16
    Registered User
    Join Date
    May 2010
    Posts
    62
    This could be a stupid question and already answered before but what exactly do you mean by flushing the stream?

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Forced the data to to be seen at the screen (usually data is accumulated in a buffer and sent to the screen simultaneously because sending data to the screen is very slow).
    I'd write it as:
    Code:
    #include<iostream>
    
    using std::cout;
    using std::endl;
    
    int main()
    {
        cout <<
            "#include<iostream>\n"
            "\n"
            "int main()\n"
            "{\n"
            "\tstd::cout << \"Hello, world!\" << std::endl\n"
            "\n"
            "\treturn 0;\n"
            "}";
        return 0;
    }
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Quote Originally Posted by Elysia View Post
    Forced the data to to be seen at the screen (usually data is accumulated in a buffer and sent to the screen simultaneously because sending data to the screen is very slow).
    I'd write it as:
    Code:
    #include<iostream>
    
    using std::cout;
    using std::endl;
    
    int main()
    {
        cout <<
            "#include<iostream>\n"
            "\n"
            "int main()\n"
            "{\n"
            "std::cout << \"Hello, world!\" << std::endl\n"
            "\n"
            "return 0;\n"
            "}";
        return 0;
    }
    Sorry for crashing the thread, but I often wondered why you would use endl over \n. So basically endl has greater overhead than \n?

  4. #19
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Yes it would, since it would flush the output buffer.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #20
    Registered User
    Join Date
    Feb 2009
    Posts
    329
    Quote Originally Posted by Elysia View Post
    Yes it would, since it would flush the output buffer.
    So if you just use \n. the output buffer would be flushed in a single go or when the buffer is full?

  6. #21
    Registered User
    Join Date
    May 2010
    Posts
    62
    Not to be rude and interrupt the two of you but do you mean that using "endl" would make a separate call to the standard library therefor making it more slow then using \n?

  7. #22
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by Kitt3n View Post
    Not to be rude and interrupt the two of you but do you mean that using "endl" would make a separate call to the standard library therefor making it more slow then using \n?
    I believe so, yes, since std::endl is actually a function. Hence it would flush everytime endl is called. While if you use "\n" if would probably only flush once (after you've printed the whole thing).
    Can't say I know all the details, but this is the principle, at least.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,739
    Quote Originally Posted by Kitt3n
    Not to be rude and interrupt the two of you but do you mean that using "endl" would make a separate call to the standard library therefor making it more slow then using \n?
    Yes, though the forced flushing of the output buffer when encountering std::endl is more likely to be the main factor in slowing down the overall speed of output.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #24
    Registered User
    Join Date
    May 2010
    Posts
    62
    Thanks for the explanation.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. malloc problem
    By Tool in forum C Programming
    Replies: 23
    Last Post: 03-12-2010, 09:54 AM
  2. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  3. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21