Clearscreen, no, not the usual question!

This is a discussion on Clearscreen, no, not the usual question! within the C++ Programming forums, part of the General Programming Boards category; Hello, I use the function Clrscr(), you know, the one from the FAQ. However, when I do this: Code: cout<<"test"; ...

  1. #1
    Unregistered
    Guest

    Question Clearscreen, no, not the usual question!

    Hello, I use the function Clrscr(), you know, the one from the FAQ.
    However, when I do this:
    Code:
    cout<<"test";
    clrscr();
    cout<<"only this text should appear";
    it doesn't do the clear screen! Instead, it displays this:
    testonly this text should appear
    But, when I do this:
    Code:
    cout<<"test"<<endl;
    clrscr();
    cout<<"only this text should appear";
    so with the endl, it works correct! Now it only displays:
    only this text should appear
    How is this possible? Why do I have to do endl before the function will work?

    btw this is the function:
    Code:
    void clrscr()
    {
       COORD coordScreen = { 0, 0 };
       DWORD cCharsWritten;
       CONSOLE_SCREEN_BUFFER_INFO csbi;
       DWORD dwConSize;
       HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
       GetConsoleScreenBufferInfo(hConsole, &csbi);
       dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
       FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
       GetConsoleScreenBufferInfo(hConsole, &csbi);
       FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
       SetConsoleCursorPosition(hConsole, coordScreen);
    }

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    cout uses a buffer. endl flushes the buffer. Alternatively you can use flush(or obtain input using cin) if you don't require a '\n'.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    30
    even better, modify your clear function, just overload it to call the flush() for you then call the one you listed, or add it to the one you listed...

  4. #4
    Unregistered
    Guest
    Thanx for the reply's both! I'll go and try it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 01:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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