Thread: window closing prematurely

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

    window closing prematurely

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      char name[20];
    
    cout<<"Please enter your name: ";
    cin>> name[20];
    cin.ignore();
    cout << "\n" <<name<< "" <<endl;
    cout << "Press enter to exit" << endl;
    cin.ignore();
    return 0;
    }
    After the name is enterd, and the user presses enter, the window closes without doing the other things.

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Add a cin.get() at the end to pause the program.

    get rid of the [20]

    near cin>>name[20]
    Last edited by treenef; 08-15-2005 at 04:27 AM.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,664
    Read the FAQ
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Learn the C++ string class even if your tutorial doesn't teach it first. It is preferred over C style strings (that you are using) in C++.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM