Thread: Question

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    7

    Question

    I'm new to C++ and I have 2 questions. I'm using Microsoft Visual C++ and I want to know why do I have to write "using namespace std;" everytime. In BC++ that's not necessary. After I build any program in MVC++ the results dissapears very quick. I have to write system("pause"); at the end of the code everytime just to get to see the result. Is there any other way I can stop it from exiting before I get to see the result?

  2. #2
    Sanity is for the weak! beene's Avatar
    Join Date
    Jul 2006
    Posts
    321
    Use cin.get();

    Example:
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
       cout << "C++ rules!" << endl;
       cin.get();
       return 0;
    }

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Sessaru
    After I build any program in MVC++ the results dissapears very quick. I have to write system("pause"); at the end of the code everytime just to get to see the result. Is there any other way I can stop it from exiting before I get to see the result?
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    I'm using Microsoft Visual C++ and I want to know why do I have to write "using namespace std;"
    I suppose that Borland is not standard compiled and does not places the C++ objects like cout into the std namespace like standard requires.
    VC++ otherwise does it, so you should place using namespace std; at the beginning of the file or preceide each object with std:: prefix to explicetly specify that it is located in the std namespace. This is the better way to do to avoid name callisions (the actual purpose of introduction namespaces)

    Code:
    int main()
    {
       std::cout<<"Hello"<<std::endl;
    }
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    In some versions of MSVC++ - you can compile & run your program using the hotkey combination CTRL + F5. This sets up the windows console to remain open after the program falls off the end of main().

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