Well, once again, hello. I'm trying to figure out why when i use 2 cin.getlines after eachother it skips one of them and I cant use it. Take a look if you will:
cout << "Welcome New Member, Please Enter a New Username and Password:\n\n";
cout << "Username: ";
cin.getline(Username, 255);
DataBase << Username << "\n";
cout << "\nPassword: ";
cin.getline(Password, 255);
DataBase << Password << "\n\n";
cout << "\nSaved To Database!\n";
DataBase.close();
delete[] Username;
delete[] Password;
}
for some reason when I run the program and goto this function it will skip the first cin.getline and only let me type for the cin.getline that gets the Password. It's wierd because I ran a simple program similar to it, and it works fine:
This code doesnt skip any cin.getline()'s for some reason, could it not work in the other one because of the file i/o? Maybe its making it act wierd? Any help is appreciated, thanks in advance.
Most probably, they would leave a newline behind, in the input stream. Hence, the first getline() used after cin would just 'eat' that newline, and wont take any input.
You should better keep habit of using cin.ignore() to flush the input stream before using getline ( or even cin; i had faced this problem in that too..tho not so sure )
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.