Thread: Problem with code (newbie question)

  1. #1

    Talking Problem with code (newbie question)

    #include <stdlib.h>
    #include <iostream.h>

    int main(void)
    int i;

    for (i = 0; i < 1000; i++)


    return 0;

    Well when I run this program there is still a little bit of 0101011101100.... and the screen was not totally cleared. :*(

    thanks in advance

  2. #2
    Add the line:
    just before the call to system("cls")

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    i think the program cleared the screen before printing all of the data out. i'm not really sure on this, though.

    one technical warning: you don't need another i++ at the end of the for loop. the one in the declaration should do the job fine. if you want to skip 2 each iteraton, do i+=2;

    //edit: beaten...
    endl flushes the output buffer, so that should do the trick

  4. #4

    Thumbs up

    Thanks Unregistered. Ive been banging my head against the wall tyring to figure this out and the answer is so simple! hehe.

  5. #5
    I posted reply #2 above. I think the technical answer to this is that the cout object ( a global instance of a class ) has an internal buffer that is not immediately flushed to the Windows screen buffer. Your output fills the cout buffer, & is flushed, then the remainder is written to the cout buffer, and is not flushed. Then you clear the screen. Then the program exits, causing the cout object's destructor to fire off, which flushes the remaining portion of the buffer to the screen buffer. Just a guess on all that.

  6. #6
    Registered User
    Join Date
    Jul 2002
    One really shoudnt use system() calls in the first place, though. Check out the faq.
    Turn no more aside and brood
    Upon love's bitter mysteries
    For Fergus rules the brazen cars...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Odd problem in main(), code won't proceed
    By aciarlillo in forum C++ Programming
    Replies: 1
    Last Post: 06-05-2005, 11:00 PM
  2. Problem using java programs within C code
    By lemania in forum Linux Programming
    Replies: 1
    Last Post: 05-08-2005, 02:02 AM
  3. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  4. Newbie question on numbers.
    By thes in forum C++ Programming
    Replies: 14
    Last Post: 06-17-2002, 07:18 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM