cin.getline function does'nt gets executed for the second time

Discussion in 'C++' started by akshatmaltare05, Aug 10, 2011.

  1. akshatmaltare05

    akshatmaltare05 New Member

    Joined:
    Aug 10, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<iostream>
    #include<stdlib.h>
    using namespace std;
    int main()
    {
            int numnonterm;
            char terminal[10];
            char nonterminal[10][10];
            char tempterminal[10];
            cout<<"enter the terminals used";
            cin.getline (terminal,10);
            cout<<"enter the no of non terminal elements";
            cin>>numnonterm;
            cout<<"enter the nonterminals";
            cin.getline(tempterminal,10);
            
            if(int i=0)
            {
                    return(0);
            }
    }
    the program exits without waiting for the user to enter the tempterm string .
    have tried it several times but is not working
    why?
     
    Last edited by a moderator: Aug 10, 2011
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Use fflush before the cin and that should work.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice