stc
Loading...
Searching...
No Matches
Public Member Functions | List of all members
stc::PasswordIO Class Reference

#include <IO.hpp>

Public Member Functions

 PasswordIO ()
 
 ~PasswordIO ()
 
void release ()
 

Detailed Description

Helper class for taking password input.

Example use:

std::string password;
// Create a scope for the password input. You don't have to create a scope; you can also just call .release(). This
// is just my personal preference, as anything inside the scope is clearly password input, while everything outside
// isn't. This eliminates bugs from taking extra input and accidentally putting it before .release()
{
// Sets the flags that hides password input
std::string password;
// You can get the password from stdin as usual
std::getline(std::cin, password);
} // Once `io` goes out of scope, input echoing is reenabled
if (password == "1234") { ... }
Definition IO.hpp:38

Warning: This class is not thread-safe. It's possible for one thread to acquire the lock, and a different thread to immediately release it afterwards. It's recommended to limit use of this function to the main thread (or a thread acting as the main thread for input, if applicable). If you really need to use this on several threads, it must be combined with a mutex or similar.

Constructor & Destructor Documentation

◆ PasswordIO()

stc::PasswordIO::PasswordIO ( )
inline

◆ ~PasswordIO()

stc::PasswordIO::~PasswordIO ( )
inline

Member Function Documentation

◆ release()

void stc::PasswordIO::release ( )
inline

The documentation for this class was generated from the following file: