prog für password funztz i-wie nich
-
Hat sich erledigt, hab gar nicht gesehen, dass ich nur ein Gleichzeichen geschrieben hab.
-
steht in jeder C++-Referenz unter "strings"
www.cplusplus.com/reference
www.cppreference.com
-
empty() ...
#if !defined(PASSWORD_HPP__INCLUDED) #define PASSWORD_HPP__INCLUDED #if (_MSC_VER >= 1300) #pragma once #endif // (_MSC_VER >= 1300) #include <string> // std::string class Password { std::string m_current; public: Password(std::string const& password) : m_current(password) {} public: bool set(std::string const& password, std::string const& new_password) { if (m_current != password) return false; m_current = new_password; return true; } std::string const& get() const { return m_current; } }; #endif // PASSWORD_HPP__INCLUDED#include "password.hpp" #include <iostream> #include <string> int main() { Password password("test"); for (unsigned char i(1); i <= 3; ++i) { std::cout << "Passwort: "; std::string password; std::getline(std::cin, password); std::cout << "Neues Passwort: "; std::string password_new; std::getline(std::cin, password if (password.set(password, new_password) == false) std::cerr << "FEHLER: Falsches Passwort eingegeben! (Noch " << 3 - i << " Versuche)" << std::endl; else break; } std::cout << "Passwort: " << password.get() << std::endl; std::cin.get(); }So hast du es mal anständig unterteilt. Die Klasse Password lässt nur zu, das du ein neues Passwort setzt (set), wenn das Passwort stimmt. Insgesamt hat man 3 Versuche das Password richtig einzugeben (for 1 ... 3).
So in etwa das was du haben willst?
Wäre vllt jetzt ganz gut das m_current noch zu verschlüsseln usw
