getline function skipping function

Is the getline function supposed to stop and allow the user to enter info? How can I get it to do this? The display shows: Enter name. Enter number. Then it waits for the user. Any suggestions? It is not allowing the user time to enter a name.





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void new_entry (ofstream& fout)
{
     char ans;
     open_out (fout);
     char name[NAME_MAX], number[NAME_MAX];
    
     cout << "Enter name." << endl;
     cin.getline(name, 199);
     cout << name;
     
     
     
     cout << "Enter number." << endl;
     cin.getline(number, 199);
     fout << number << endl;
     fout.clear();
     fout.close();
}
     
Last edited on
Are you using the extraction operator on cin e.g cin >> somewhere in your program before calling this function?
Topic archived. No new replies allowed.