I need help with my code

I need help it skips the cin.getline in my if stat mint and I have no clue why?
ps.I am using visual c++


#include <iostream>
#include <fstream>//libry I think I need
#include <string>
using namespace std;


int main () {
ofstream myfile ("example.txt");
ifstream file ("example.txt", ios::in|ios::binary|ios::app|ios::out);
char name[20],lname[20],midname[20],house[20],street[20],state[20],cuntry[20],num[15]
,city[20],h[20];//my vireables
string no;
if (file.is_open())
{

cout << "new user or old: " << endl;
cin >> no;
if (no=="new")
{

cout << "";/* needed to make the code work idk why the code skips the
cin.getline (h,20);//first cin hope you can see why.

cout << "first name: " << endl ;
cin.getline (name,20);

cout << "midil name: " << endl ;
cin.getline (midname,20);

cout << "last name: " << endl ;
cin.getline (lname,20);

myfile << "name: " << name << " " << midname << " " << lname << endl;

cout << "\nadres house number: " ;
cin.getline (house,20);

cout << "\nstreet: ";
cin.getline (street,20);

cout << "\ncity: ";
cin.getline (city,20);

cout << "\nstate: ";
cin.getline (state,20);

cout << "\ncuntry: ";
cin.getline (cuntry,20);

myfile << "adres: " << house << " " << street << " " << city << " " << state << " " << cuntry << endl;
cout << "phone number 000-000-0000: ";
cin.getline (num,15);
myfile << "phone number: " << num ;
}
else
{

}
file.close();
}
else cout << "Unable to open file";

system ("pause");
return 0;
}
Add cin.ignore before cin.getline :

1
2
3
4
cout << "";// needed to make the code work idk why the code skips the 
cin.ignore( 100, '\n' );
cin.getline (h,20);//first cin hope you can see why.
Topic archived. No new replies allowed.