title: Optimize inserting std::uint32_t's into a std::vector<char>
body: <p>I'm attempting to insert an array of unsigned ints into a std::vector.</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>auto add_chars(std::vector&lt;char&gt; &amp; vec, unsigned val[]){
      std::string tmp;
      tmp.resize(11) // Max chars a uint can be represented by, including the '\n' for sprintf
      for (auto x = 0; x&lt; 10; x++){
          auto char_count = sprintf(tmp.data(),"%u", val[x]);
          vec.insert(vec.begin()+vec.size(),tmp.data(), tmp.data()+char_count);
      }
  
  }
  
  int main(){
      std::vector&lt;char&gt; chars;
      unsigned val[10] {1,200,3,4,5,6000,7,8,9000};
      add_chars(chars,val);
      for (auto &amp; item : chars){
          std::cout &lt;&lt; item;
      }
  }
  </code></pre>
  
  <p>This solution works, however I question its efficiency (and elegance).</p>
  
  <p>Two questions:</p>
  
  <ul>
  <li>Is there a more idiomatic way of doing this?</li>
  <li>Is there a more efficient way of doing this?</li>
  </ul>
  
  <p>*edit Fixed a bug in the code made while transferring over to here.</p>
  
  <p>Also, i'm aware that '9000' can't be represented as 1 char, whats why im using the buffer and sprintf to generate multiple chars for the one uint.</p>