dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12
  1. #1
    Chad Gorshing Guest

    system("cls") to slow


    When I use 'system("cls")' there is a delay about a second's worth. In DOS
    when I type cls, there is no delay.

    What gives?

  2. #2
    Luis Abreu Guest

    Re: system("cls") to slow


    If you're using VC++ ( win32 console application ) then you can always use
    the console functions to clean the screen. there's a sample about it in msdn.microsoft.com

  3. #3
    never worked Guest

    Re: system("cls") to slow


    "Luis Abreu" <luisabreu@netmadeira> wrote:
    >
    >If you're using VC++ ( win32 console application ) then you can always use
    >the console functions to clean the screen. there's a sample about it in

    msdn.microsoft.com

    I've never gotten this function to work.
    I've see many respones directing people here,
    but have they tried this function themselves??
    Has anyone gotten this thing to work properly?

  4. #4
    Jason Guest

    Re: system("cls") to slow


    "never worked" <neverworked@never> wrote:
    >
    >"Luis Abreu" <luisabreu@netmadeira> wrote:
    >>
    >>If you're using VC++ ( win32 console application ) then you can always

    use
    >>the console functions to clean the screen. there's a sample about it in

    >msdn.microsoft.com
    >
    >I've never gotten this function to work.
    >I've see many respones directing people here,
    >but have they tried this function themselves??
    >Has anyone gotten this thing to work properly?



    Yes, Use the GNU g++ compiler. It works fine with that. VC++ is terrible
    with system calls. Try searching for DJGPP or cygwin for WIN32 GNU tools.


  5. #5
    Nick G-B Guest

    Re: system("cls") to slow


    "Jason" <kahuna01@hotmail.com> wrote:
    >
    >"never worked" <neverworked@never> wrote:
    >>
    >>"Luis Abreu" <luisabreu@netmadeira> wrote:
    >>>
    >>>If you're using VC++ ( win32 console application ) then you can always

    >use
    >>>the console functions to clean the screen. there's a sample about it in

    >>msdn.microsoft.com
    >>
    >>I've never gotten this function to work.
    >>I've see many respones directing people here,
    >>but have they tried this function themselves??
    >>Has anyone gotten this thing to work properly?

    >
    >
    >Yes, Use the GNU g++ compiler. It works fine with that. VC++ is terrible
    >with system calls. Try searching for DJGPP or cygwin for WIN32 GNU tools.
    >

    Oh come on, just use that trusty asm{} block! :) Gets rid of timing delays,
    and household pets if you're not careful...

  6. #6
    Jason Guest

    Re: system("cls") to slow


    "Nick G-B" <nickgb@antisocial.com> wrote:
    >
    >"Jason" <kahuna01@hotmail.com> wrote:
    >>
    >>"never worked" <neverworked@never> wrote:
    >>>
    >>>"Luis Abreu" <luisabreu@netmadeira> wrote:
    >>>>
    >>>>If you're using VC++ ( win32 console application ) then you can always

    >>use
    >>>>the console functions to clean the screen. there's a sample about it

    in
    >>>msdn.microsoft.com
    >>>
    >>>I've never gotten this function to work.
    >>>I've see many respones directing people here,
    >>>but have they tried this function themselves??
    >>>Has anyone gotten this thing to work properly?

    >>
    >>
    >>Yes, Use the GNU g++ compiler. It works fine with that. VC++ is terrible
    >>with system calls. Try searching for DJGPP or cygwin for WIN32 GNU tools.
    >>

    >Oh come on, just use that trusty asm{} block! :) Gets rid of timing delays,
    >and household pets if you're not careful...



  7. #7
    Jason Guest

    Re: system("cls") to slow


    One more Idea that pops into my head is to make your own screenclear function.
    I was reading Danny Kalev's post about multiple lines and got an idea (i
    dont know if its been used before).

    int ScreenClear(const int ScreenRows)
    {
    if (ScreenRows < 0 || ScreenRows > MAXROWS) {
    cerr << "The Screen Does not support this number
    of rows.";

    return 1;
    }

    for(int i = ScreenRows; i > 0; --i) cout << '\n';

    return 0;
    }

    This function depends on MAXROWS being defined somewhere in the scope of
    the function. MAXROWS will depend on the size of your Console, Xterm, or
    DOS window.
    If anyone has even more ideas please post a reply.

    best wishes,
    Jason


  8. #8
    Nickolaus Guest

    Re: system("cls") to slow


    This is a great idea and all, but how does it's speed compare to that of system(
    "cls" )? Condsidering it has to collect values for ScreenRows and MAXROWS.


    -Nickolaus


    "Jason" <kahuna01@hotmail.com> wrote:
    >
    >One more Idea that pops into my head is to make your own screenclear function.
    >I was reading Danny Kalev's post about multiple lines and got an idea (i
    >dont know if its been used before).
    >
    >int ScreenClear(const int ScreenRows)
    >{
    > if (ScreenRows < 0 || ScreenRows > MAXROWS) {
    > cerr << "The Screen Does not support this number
    > of rows.";
    >
    > return 1;
    > }
    >
    > for(int i = ScreenRows; i > 0; --i) cout << '\n';
    >
    > return 0;
    >}
    >
    >This function depends on MAXROWS being defined somewhere in the scope of
    >the function. MAXROWS will depend on the size of your Console, Xterm, or
    >DOS window.
    >If anyone has even more ideas please post a reply.
    >
    >best wishes,
    >Jason
    >



  9. #9
    Jason Guest

    Re: system("cls") to slow


    "Nickolaus" <watts.77@osu.edu> wrote:
    >
    >This is a great idea and all, but how does it's speed compare to that of

    system(
    >"cls" )? Condsidering it has to collect values for ScreenRows and MAXROWS.
    >
    >
    >-Nickolaus
    >


    With The GNU C++ compiler, the speed will be slightly slower using the function,
    but with Visual C++ (the compiler that was being used with the original question)
    the function is much, much faster. Ive never tried the ASM code block that
    some people recommend for VC++, but I imagine that its faster than system("cls");
    also.

    Jason


  10. #10
    Justin Arruda Guest

    Re: system("cls") to slow


    This probably won't answer any questions, but I hope to get this answered.
    I must have missed something, but what even happened to clrscr(); in C.
    I remember using it all the time and it was fast for me. Can someone tell
    me why is was all of a sudden upsupported?

    "Jason" <kahuna01@hotmail.com> wrote:
    >
    >"Nickolaus" <watts.77@osu.edu> wrote:
    >>
    >>This is a great idea and all, but how does it's speed compare to that of

    >system(
    >>"cls" )? Condsidering it has to collect values for ScreenRows and MAXROWS.
    >>
    >>
    >>-Nickolaus
    >>

    >
    >With The GNU C++ compiler, the speed will be slightly slower using the function,
    >but with Visual C++ (the compiler that was being used with the original

    question)
    >the function is much, much faster. Ive never tried the ASM code block that
    >some people recommend for VC++, but I imagine that its faster than system("cls");
    >also.
    >
    >Jason
    >



  11. #11
    Join Date
    Jan 2018
    Posts
    1
    It's been 18 years .


    I found the answer on this website.


    http://www.cplusplus.com/forum/beginner/100115/

    Answered by JLBorges:

    > I'm getting an explosion of syntax errors as soon as I #include windows.h.

    There are name clashes with macros defined in <windows.h>

    So, insulate the windows stuff in a separate component:

    Header cls.h




    #ifndef CLS_H_INCLUDED
    #define CLS_H_INCLUDED

    void cls() ;

    #endif // CLS_H_INCLUDED




    Implementation cls.cc



    #include "cls.h"
    #include <windows.h>

    void cls()
    {
    HANDLE console = ::GetStdHandle(STD_OUTPUT_HANDLE) ;
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    ::GetConsoleScreenBufferInfo( console, &csbi );
    COORD origin = { 0, 0 } ;
    DWORD written ;
    ::FillConsoleOutputCharacterA( console, ' ' , csbi.dwSize.X * csbi.dwSize.Y,
    origin, &written );
    ::FillConsoleOutputAttribute( console, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y,
    origin, &written );
    ::SetConsoleCursorPosition( console, origin );
    }




    And then #include "cls.h" in those translation units where you want to call cls();

  12. #12
    Join Date
    Jan 2018
    Posts
    14
    [When posting code, please use code tags so that the code is readable. Either include the tags at the start and end of the code or Go Advanced, select the formatted code and click '#'.]

    system("cls") is slightly slower than using cls at dos prompt as system() first creates a new process which executes the supplied command.

    clrscr() originated from Borland turbo c/c++. It was defined in conio.h and is non-standard. Whether clrscr() is supported by a particular compiler depends upon the compiler - it is implementation specific. It is not supported by Microsoft VS.
    Last edited by 2kaud; 01-22-2018 at 04:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center