Thread: Got A Question

  1. #1
    Fallen AndyBomstad's Avatar
    Join Date
    Jan 2005
    Posts
    52

    Got A Question

    ok so while im writing my sys32 files i run into using
    Code:
    system("cls");
    alot and now im trying to figure out if i can creat a global variable to atomaticly substitute that line in for the word "Clear" or somthing simple

    i basicly only want to type clear while im writing my file and have the compiler recognize it for the system("cls") command anyways if ya guy could help out it would be great

  2. #2
    Fallen AndyBomstad's Avatar
    Join Date
    Jan 2005
    Posts
    52
    or if you guys could help me write a header file to do it or somthing just tell me what my options are lol

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    ?
    Code:
    #define Clear system("cls")
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  4. #4
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    A couple options:

    Code:
    // option1:
    # define CLEAR system("cls")
    
    // option2:
    void clear() {
        system("cls");
    }
    
    int main() {
        // option 1 in use:
        CLEAR;
    
        // option 2 in use:
        clear();
    
        return 0;
    }
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    56
    Really.. That just isn't a very good programming practice... But if you insist..

    Code:
    #include <iostream>
    #include <cstdlib>
    
    #define CLEAR system("cls");
    
    int main()
    {
        std::cout << "yo!" << endl;
        CLEAR
        
        return 0;
    }
    system() is bad news.. Check out these options instead of using system("cls") - http://faq.cprogramming.com/cgi-bin/...&id=1043284385

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well first of all, I'd use a different method for clearing the screen (http://www.cprogramming.com/tips/sho...unt=30&page=0). Some better alternatives might be found at http://faq.cprogramming.com/cgi-bin/...&id=1043284385.

    What I'd do is just put the code from the option of your choice in it's own function (perhaps, "clear()")and add that to your code files. As you get more advanced you may want to put that in a library with some other commonly used functions, and set it up so all you have to do is "include" your custom library.

  7. #7
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    system() is horrible. Don't use it. It's system-dependent and may not run on other machines, it's SLOW, and anyone can screw with CLS.exe to make it a virus or something without your knowledge. It's dangerous, slow, and totally NOT portable.

    3 reasons why system() sucks.
    Last edited by Krak; 03-10-2005 at 08:59 PM.

  8. #8
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    @Krak:
    system() is not *quite* as dangerous as you think:
    http://cboard.cprogramming.com/showt...ghlight=system

    Although the other two points do hold valid.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  9. #9
    Fallen AndyBomstad's Avatar
    Join Date
    Jan 2005
    Posts
    52
    Lol Omg...im sorry guys... it was late last night and i really cant believe i let that slip me by....
    Code:
    // option2:
    void clear() {
        system("cls");
    }
    just make a function... ive done stuff like that a million times.. but nooo i couldnt think ta do that last night LOL.. but anyways thanks alot guys lol sorry im a newb

  10. #10
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Quote Originally Posted by AndyBomstad
    Lol Omg...im sorry guys... it was late last night and i really cant believe i let that slip me by....
    Code:
    // option2:
    void clear() {
        system("cls");
    }
    just make a function... ive done stuff like that a million times.. but nooo i couldnt think ta do that last night LOL.. but anyways thanks alot guys lol sorry im a newb
    Ummm...yeah...ignore the fact that we've been talking about how evil system() is and how much it sucks.

Popular pages Recent additions subscribe to a feed

Similar Threads

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