Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   cin.getline function does'nt gets executed for the second time (http://www.go4expert.com/forums/cingetline-function-doesnt-executed-time-t26475/)

akshatmaltare05 10Aug2011 17:50

cin.getline function does'nt gets executed for the second time
 
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?

shabbir 10Aug2011 21:36

Re: cin.getline function does'nt gets executed for the second time
 
Use fflush before the cin and that should work.


All times are GMT +5.5. The time now is 22:18.