title: How can I create dynamic array without asking user to enter a size in C++?
body: <p>I want to take 8 char password from user and then when she/he wanted to enter, I wanted it to be whatever size she/he enter. However, the code doesn't stop until it reaches 8 char, even I press 'enter', it takes it as a char and create '*'. I want its size to be whatever user write and then user press 'enter', it will take these characters as password to see if it is matched with registered password. For example;</p>
  <ul>
  <li>User register password as 'wellcode'</li>
  <li>After that, user write in login screen 'well' then enter(in my code it lasts until I reach 8 characte</li>
  <li>'Login failed! will be written</li>
  </ul>
  <p>Is there a way to do that in C++?</p>
  <pre><code>    bool CheckCredentials(string);
         char pass[8], inPass[8];
         int main()
          {
              fstream encrypted;
              bool done = false;
              while (!done)
              {
                  cout &lt;&lt; &quot;1. Register a password&quot; &lt;&lt; endl;
                  cout &lt;&lt; &quot;2. Login your password&quot; &lt;&lt; endl;
                  cout &lt;&lt; &quot;3. Exit&quot; &lt;&lt; endl;
                  
                  int menuChoice;
                  cin &gt;&gt; menuChoice;
          
                  if (menuChoice == 1)
                  {
                      
                      ifstream ifile;
                      ifile.open(&quot;password.txt&quot;);
                      if (ifile){}
                      else
                      {
                          cout &lt;&lt; &quot;New password must contain only 8 characters: &quot;;
                          for (int i = 0; i &lt; 8; i++)
                          {
                              pass[i] = _getch(); _putch('*');
                          }
                          ofstream l(&quot;password.txt&quot;, ios::out);
                          if (!l.is_open()) {
                              cout &lt;&lt; &quot;could not open file \n&quot;;
                          }
                          for (int i = 0; i &lt; 8; i++)
                          {
                              l &lt;&lt; pass[i];
                          }
                          l.close();
                          cout &lt;&lt; &quot;\n\n&quot;;
                      }
                  }
          
                  else if (menuChoice == 2)
                  {
          
                          cout &lt;&lt; &quot;Password: &quot;;
                          for (int i = 0; i &lt; 8; i++)
                          {
                              inPass[i] = _getch(); _putch('*');
                          }
          
          
                          if (CheckCredentials(inPass) == true)
                          {
                              cout &lt;&lt; &quot;\nLogin sucessful!&quot; &lt;&lt; &quot;\n\n&quot;;
                          }
                          else
                          {
                              cout &lt;&lt; &quot;\nLogin failed!&quot;
                          }
          
                  }
                  else if (menuChoice == 3)
                  {
                      done = true;
                      break;
                  }
              }
          
              return 0;
          }
  
  bool CheckCredentials(string inPass)
  {
      string s;
  
      bool status = false;
  
      ifstream f;
      f.open(&quot;password.txt&quot;);
  
      if (!f.is_open())
      {
          cout &lt;&lt; &quot;Unable to open file!\n&quot;;
      }
      else if (f)
      {
          while (!f.eof())
          {
              f &gt;&gt; s;
  
              if (inPass == s)
              {
                  status = true;
              }
              else
              {
                  status = false;
              }
          }
      }
  
      f.close();
      return status;
  }
  </code></pre>