login code in c++ code example

Example: how to make a login c++

// a simple login for c++ using while loops and io (input output)
#include <iostream>
#include <string>

using namespace std;

int main() {
  cout << "please enter password";
  string pass = "0";                  // making a string for user input
  cin >> pass;                        // could be replaced with getline(cin, pass);
  while (pass = "1234") {             // while loop for when password is wrong
    cout << "incorrect, try again";
    cin >> pass;                      // could be replaced with getline(cin, pass);
  }
  cout << "correct password";         // runs when the while loop is no longer happening
}

Tags:

Cpp Example