title: Create string of specific length in C++
body: <p>For my class, I have to take three strings, then center them.</p>
  
  <p>Here's a link to the problem, and no, I'm not asking for the answer to the problem!<br>
  <a href="http://www.hpcodewars.org/past/cw3/problems/Prog05.htm" rel="noreferrer">http://www.hpcodewars.org/past/cw3/problems/Prog05.htm</a></p>
  
  <p>I have everything I need, but I need to create a string of "*" with a specific length. In this case, it needs to be 21 characters long of asterisks, and I don't know how to create that.</p>
  
  <p>I mean, yeah, I can do</p>
  
  <pre><code>string test = "********************"
  </code></pre>
  
  <p>but it needs to be a different length as it changes.</p>
  
  <p>I have a variable set to how long the string needs to be, but I need to know how to create a string with a specific length, then add in the asterisks. </p>
  
  <p>Code so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
      string line;
      string lines[2];
      int x = 0;
      int maxLength;
      ifstream myfile ("example.txt");
  
      if (myfile.is_open()) // opening file, setting the strings in the input stream to a variable to use at a later time
      {
          while ( getline (myfile,line) )
          {
              lines[x] = line;
              x++;
          }
          myfile.close();
      }
  
      if(lines[0].length() &gt; lines[1].length()) //finding the max length;
      {
          maxLength = lines[0].length();
      }else
      {
          maxLength = lines[1].length();
      }
      if(lines[2].length() &gt; maxLength)
      {
          maxLength = lines[2].length();
      }
  
      maxLength = maxLength + 4;
  
      cout&lt;&lt;maxLength&lt;&lt;endl;
  
      return 0;
  }
  </code></pre>