clear screen code, can't get it to work

This is a discussion on clear screen code, can't get it to work within the C++ Programming forums, part of the General Programming Boards category; I'm trying to call a clear screen function in my program but I get this error: 'clrscr' : undeclared identifier. ...

  1. #1

    Unhappy clear screen code, can't get it to work

    I'm trying to call a clear screen function in my program but I get this error: 'clrscr' : undeclared identifier. What am I doing wrong???

    void clrsc(); //clear screen function

    void clrsc()

    then here's my complete code calling function clrsc():

    Register reg1;
    //cout << "Clear the screen here ****";

    cin >> selec2;
    if (selec2 == 1)
    cout << "quantity: ";
    cin >> quantity;
    cout << "price: ";
    cin >> price;

    reg1.ring(quantity, price);
    else if (selec2 == 2)
    cout << "Your total is: " << reg1.findtotal() << "Please insert your tender: ";
    cin >> tender;
    cout << "your change is " <<;
    else if (selec2 == 3)
    else if (selec2 == 4)
    cout << "How much we got?";
    cin >> whatwegot;
    cout << "The register is at "<< reg1.reconcile(whatwegot) << " for the day.";
    else if (selec2 == 5)
    fin = true;
    cout << "Error.. try again.";

  2. #2
    clrscr() should work. Why are you calling a function that simply just calls clrscr(). It's a waste of stack space.

    Just call clrscr() and dump your function. When you call your clrsc() function it creates a new stack frame for it. This incurs a lot of pushing and popping to setup and cleanup the stack. Then you are calling the actual clrscr() with yet another call which incurs the same overhead. So, you are making your program almost twice as slow by using a function to call a function. Granted you won't notice it in this example, but it's not a good habit to get into cuz it will eventually catch up to you.
    You are doing two calls as opposed to one.

    So dump

    void clrsc(void)

    and just call clrscr() from within your loop

    Make sure you have included the correct header for clrscr()

    From my Borland help file

    #include <conio.h>
    void clrscr(void);


    Clears the text-mode window.
    clrscr clears the current text window and places the cursor in the upper left corner (at position 1,1).

    Note: Do not use this function for Win32s or Win32 GUI applications.

    Return Value


  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    clrscr() is not a standard is compiler specific.

    Have a look at our FAQ for a list of alternatives.....otherwise consult your compilers documentation

  4. #4
    #include <conio.h>

    i think thats what we use for clrscr() at my school.. see if you got the .h file and try it.


  5. #5

    thank you all

    it looks like clrscr() doesn't work with MS Visual C++ so I had to include this code to clear my screen:

    #include <windows.h>

    void clrscr()
    COORD coordScreen = { 0, 0 };
    DWORD cCharsWritten;
    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);

    thanks to the faq board..

  6. #6
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001

    the best

    use system command:


    do not change uppercase/lowercase, keep it exactly as it is above.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    >>> use system command:

    No, do it the way you've done it. Browse the FAQ for some of the many reasons using system() is a bad idea if you are targetting a Windows system.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Registered User
    Join Date
    Aug 2001
        //cout << "Clear the screen here ****"; 
    How about adding that 'r' after 'clrsc'?
    kooma -

  9. #9
    how about writing your own function:

    void clsrscr()
    for(int i = 0; i < 51; i++)
    cout << '\n'; //or cout << endl;

  10. #10
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Because it's slow and it won't work if there's more than 51 lines on the screen.

  11. #11
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    because you don know how many lines the console is!
    some are 25, some are 43 etc - and its highly inefficient - if your going to do it that way use GetConsoleScreenBuffer to reurn the Y value and use that as the variable in the loop
    Monday - what a way to spend a seventh of your life

  12. #12
    all true comments, but:

    it is ANSI compliant and OS independent,

    milliseconds are undetectable to you and I, and certainly irrelevant if the data are going to stay of the screen for user perusal anyway

    you could use 1000 or some other number rather than 51 if you are concerned about "screen size"

    and you don't need to know anything about API functions to get it to work.

    I'll take effectiveness, convenience, and portability over negligable time delays and obscurity (to those who don't know API functions) any day.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  2. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  3. Clear screen command
    By digarren in forum C++ Programming
    Replies: 10
    Last Post: 10-14-2002, 11:26 PM
  4. FYI - a simple way to clear the screen
    By johnc in forum C Programming
    Replies: 13
    Last Post: 07-17-2002, 04:53 PM
  5. clear screen
    By y2jasontario in forum C Programming
    Replies: 2
    Last Post: 04-04-2002, 11:50 AM

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