Dos program quits

This is a discussion on Dos program quits within the C++ Programming forums, part of the General Programming Boards category; Yah, so I'm trying to learn C++, I go to the first tutorial with cout , that displays simple text. ...

  1. #1
    Help Me!
    Guest

    Dos program quits

    Yah, so I'm trying to learn C++, I go to the first tutorial with cout , that displays simple text. When I test it in Borland, it opens and closes really fast, this is really annoying.... how do i fix this?

    Also, is their any hope for people who aren't super smart with computers to learn C++ ? .. And approximately how long does it take to learn for average people, thats the basics of C++ ..
    Thanks

  2. #2
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    This is in the FAQ.. but basically you need to pause the program before it completes execution. Simplest way is to ask the user for input. This will pause the program until you enter something... like such.

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main(void)
    {
    	cout << "If I don't pause by waiting for input, I will close!" << endl;
    
    	cin.get();  // Ask the user for input
    
    	return 0;
    }

  3. #3
    Registered User codingmaster's Avatar
    Join Date
    Sep 2002
    Posts
    309
    You can use system("pause"); too

    Code:
    #include <iostream>
    using namespace std;
    
    int main()		// int main() never returns a void, main returns always int
    {
    	cout << "YOUR OUTPUT" << endl;
    
    	system("pause");
    	
    	return 0;
    }
    I'm sure, that there is a keyboard combination like Ctrl + F5 (Visual Studio) to let the window open for your C++ IDE

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    5
    when u create a consol app in Borland or Visual c++ u can hold the scrren by asking the user to enter a char or something.

    in borland --- getchar();

    this function hold ur screen and u can exit the screen by pressing Enter key.
    Last edited by Amar; 05-25-2003 at 03:26 PM.

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    try using the getch function. works for me. just add it right before your return statement and make sure to add the conio.h header file

    Code:
    #INCLUDE <iostream.h>
    #include <conio.h>// for getch()
    
    int main()
    
    {
    
    cout << "My screen wont close no more";
    getch(); //this waits for a user to entre any key before it closes
    return 0;
    }
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  6. #6
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    best is system("PAUSE");
    it gives you the press any key to continue message

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by Iamien
    best is system("PAUSE");
    it gives you the press any key to continue message
    You could just type that in. It's only one more line of code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. program quits when using getline..
    By gL_nEwB in forum C++ Programming
    Replies: 9
    Last Post: 05-20-2006, 05:16 PM
  4. initialising a DOS program from a C enviroment
    By Robert_Ingleby in forum C Programming
    Replies: 5
    Last Post: 03-07-2002, 12:53 PM
  5. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 12:42 PM

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