title: Function exceeds stack size, consider moving some data to heap (C6262)
body: <p>I'm trying to learn C++ by making a password generator, and when I was almost done, I had a warning (Warning    C6262   Function uses '20044' bytes of stack:  exceeds /analyze:stacksize '16384'.  Consider moving some data to heap.)
  And since I'm a beginner at C++ and only now the basics, I don't know what to do.</p>
  
  <p>Since I had 2 arrays in the function, I've tried to move them out of the main function, It did lower the number of bytes it was using (20100), it was still too high. I've tried to read Microsoft's errors guide, but I don't know about heaps or moving said data to the heaps in C++</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;random&gt;
  using namespace std;
  
  class Randomer {
      // random seed by default
      std::mt19937 gen_;
      std::uniform_int_distribution&lt;size_t&gt; dist_;
  
  public:
      /*  ... some convenient ctors ... */
  
      Randomer(size_t min, size_t max, unsigned int seed = std::random_device{}())
          : gen_{ seed }, dist_{ min, max } {
      }
  
      // if you want predictable numbers
      void SetSeed(unsigned int seed) {
          gen_.seed(seed);
      }
  
      size_t operator()() {
          return dist_(gen_);
      }
  };
  
  string alphabet{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
                            'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
                            'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
                            'k', 'l', 'm', 'n','o','p', 'q', 'r', 's', 't', 'u', 'v',
                            'w', 'x', 'y', 'z' };
  string specialchars{ ' ','!','#','$', '%', '&amp;','(',')','*','+','-','.','/',':',';','&lt;','=','&gt;','?','@' };
  Randomer rand1{ 0,2 };
  Randomer randint{ 0,9 };
  Randomer randalpha{ 0,26 };
  Randomer randspecial{ 0,20 };
  int main()
  {
      while (true) { //This loop is to restart the program if an invaild response is detected.
          int i;
          int lengthofpassword = 8;
  
          cout &lt;&lt; "Do you want to generate a password or to type in a existing password to make it stronger?\n\n(1 for generation, 2 for existing password)\n";
          cin &gt;&gt; i;
          int g = 0;
          if (i == 1) {
              cout &lt;&lt; "\nWhat is the length of the password?\n";
              cin &gt;&gt; lengthofpassword;
              while (g &lt;= lengthofpassword -1) {
  
                  //if (rand() == 0) {//numb
                  //  cout &lt;&lt; randint();
                  //}
                  //else if (rand() == 1) {//letter
                  //  cout &lt;&lt; alphabet[randalpha()];
                  //}
                  switch (rand1())
                  {
                  case 0:
                      cout &lt;&lt; alphabet[randalpha()];
                      break;
                  case 1:
                      cout &lt;&lt; randint();
                      break;
                  case 2:
                      cout &lt;&lt; specialchars[randspecial()];
                      break;
                  default:
                      break;
                  }
  
                  g = g + 1;
                  //cout &lt;&lt; "\n\n" &lt;&lt; g &lt;&lt; "\n\n";
              }
              cout &lt;&lt; "\n";
              system("pause");
              return 0;
  
          }
          else if (i == 2) {
              cout &lt;&lt; "\n";
              system("pause");
              return 0;
          }
          else {
              cout &lt;&lt; "\n";
              cout &lt;&lt; "Invaild Response!\n";
          }
      }
  //  system("pause");
      return 0;
  }
  </code></pre>
  
  <p>Trying to condense it for stackoverflow didn't work.
  Although it hasn't broken yet and works as expected, I feel like I should learn this type of stuff now rather than later.</p>