Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) operator&&

 

operator&& (pronounced as 'logical and operator') is an operator to state that two conditions must be true. In the example below, both a username and password must be correct.

 

 

#include <iostream>
#include <string>

int main()
{
  std::string user_name;
  std::cout << "Please enter your username\n";
  std::cin >> user_name;

  std::string password;
  std::cout << "Please enter your password\n";
  std::cin >> password;

  if (user_name == "Bilderbikkel"
    && password == "MyPassword")
  {
    std::cout << "Welcome Bilderbikkel\n";
  }
  else
  {
    std::cout << "Access failed\n";
  }
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict