title: C++ - Limit the string length
body: <p>I want to create a program that allows the user to create a password and username. However, the password must be between 6 and 10 characters. How would I limit the character input? Also, what if I want the password to include capital letters?</p>
  
  <p>Here's a look at the program so far to give you an idea of what I am trying to do (NOTE: I know the program itself is obviously unfinished but I just want to give you a visual):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  int main(int argc, const char * argv[]) {
      // insert code here...
  
      std::cout &lt;&lt; "--------------------------------------------------------------\n";
      std::cout &lt;&lt; "          Welcome to the ECE!! Password Proram!\n";
      std::cout &lt;&lt; "Username rules: must be 5-10 characters long with no space\n";
      std::cout &lt;&lt; "Password rules: must be 6+ characters long\n";
      std::cout &lt;&lt; "Must contain one uppercase letter and one number but no space\n";
      std::cout &lt;&lt; "--------------------------------------------------------------\n";
  
      //Let's get our password!
      std::string username;
      std::string password;
      const int
  
      //use a do while loop for input validation
      do {    
          std::cout &lt;&lt; "Enter your username: ";
          std::cin &gt;&gt; username;                       //add input validation               
      } while ();
  
      std::cout &lt;&lt; "Enter your password:";
      std::cin &gt;&gt; password;    
      return 0;
  }
  </code></pre>