title: How to efficiently replace characters in an std::string with iterative values from another std::string?
body: <p>I have the following strings:</p>
  
  <pre><code>std::string str1 = "1234567890";
  std::string str2 = "B-XXXX_XXX_V-XX_X";
  </code></pre>
  
  <p>I want to loop through <code>str2</code> and replace every occurrence of X with the subsequent value from <code>str1</code>, resulting in: <code>B-1234_567_V-89_0</code>. </p>
  
  <p>I have a semblance of a solution below, but it's not very efficient (it worked at one point). In brief, I tried to loop through the characters in <code>str2</code>, and if the character equaled 'X', replace that character with an incrementing index from <code>str1</code>:</p>
  
  <pre><code>  int ind = 0;
    std::string pattern_char;
    for (int i = 0; i &lt; str2.size(); i++) {
      pattern_char = str2[i];
      if (pattern_char == "X") {
        str2[i] = str1[x_ind];
        x_ind++;
      }
    }
  </code></pre>
  
  <p>What is the most efficient way to perform this operation?</p>