hi,
in code below cin.get() doesn't work correctly (maybe I'm mistaken)
first time I press Enter, cursor will come at beginning of line. and next time, new line will overwrite on what would output in next lineCode:#include <iostream> #include <string> using namespace std; void getPassword(void); bool Login(string, string); int main { string uname; string pass; int cmd; while (true) { cout << "Select your choose: " << endl << " 1. Login" << endl << " 2. What evere!" << endl << " 3. Exit" << endl; cin >> cmd; switch (cmd) { case 1: cin.ignore(); cout << "Enter username: "; getline(cin, username); cout << "Enter Passwoed: "; password = getPassword(); if (!Login(username, password)) { cout << "> Username or Password was wrong!" << endl << "> Press Enter to continue" << endl; cin.get(); // problem is here: I should press Enter twice!!? cout << endl; // and what ever cout here will be ignored break; } break; case 2: // do something break; case 3: return 0; break; } } }
I have tried different solution I found over internet but cannot solve this.
thanks in advance



LinkBack URL
About LinkBacks


