Thread: using more then one namespace? std and system? for a console app

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    16

    using more then one namespace? std and system? for a console app

    i have written a basic c++ program to the Console but which looks something like:
    Code:
    #include <iostream>
    using namespace std;
    int main();
    {
    cout<<"Hello World";
    }
    ok, there is no problems with this but, when i add a loop, i also would like to clear the screen as there are other display statements in the program now (added while going through the tutorial). what i am looking to accomplish is, clearing the console. it is my understanding that it is referanced in the System namespace or something to that effect as per msdn. how would i go about referancing this "function" of the system namespace as i have declared "using namespace std"? i tried using :
    system::console.clear();
    system::clear();
    std::system::clear(); lol
    but, the vs2003 c++ compiler i am using doesnt seem to see this as valid and, im sure for good reason but, i was hoping someone could explain how i need to do this for later use.

  2. #2
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    i think you're talking about

    Code:
    system("CLS");

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    16
    c:\My Documents\Visual Studio Projects\hello world\hello world.cpp(22): error C2065: 'CLS' : undeclared identifier
    nah that didnt do it although as i was typeing the "(" it did evalute it as a statement
    i think it was like:
    int system (const char*)
    is the syntax.....?

  4. #4
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    are you sure?

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(){
    
             cout << "something";
             system("CLS");
    
             return 0;
    
        }
    This works fine for me.

  5. #5
    Banned
    Join Date
    Jun 2005
    Posts
    594
    system() commands are not recommended for various reason,

    you shoudl check the following :

    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    16
    well, i added the code you suggested again and, this time it did compile and work. i must not have entered the syntax correctly or something i dont know..... but, thank you very much for your help.

  7. #7
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    The system() function is rarely a good idea, and in console tasks is a particulaly bad move. Clearing the screen is covered in my Console Programming Tutorial.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  8. #8
    Weak. dra's Avatar
    Join Date
    Apr 2005
    Posts
    166
    yeh...i know. I was just correcting him about the whole namespace issue thing. lol.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. noob in need of master
    By gothpunk in forum C++ Programming
    Replies: 45
    Last Post: 06-24-2005, 11:31 AM
  2. Site tutorials
    By Aalmaron in forum C++ Programming
    Replies: 20
    Last Post: 01-06-2004, 02:38 PM