title: C++ copy list of chars to string exactly without ignoring multiple whitespace
body: <p>I have a list of chars, L: </p>
  
  <pre><code>{'h','e','l','l','o',' ', ' ',' ', 'm', 'y', ' ', ' ',' ', 'n','a','m','e'};
  </code></pre>
  
  <p>I want to copy it to a string. I want to maintain triple spaces and get a string S below:</p>
  
  <pre><code>"hello   my   name"
  </code></pre>
  
  <p>I tried this:</p>
  
  <pre><code>string S(L.begin(), L.end()); 
  </code></pre>
  
  <p>but it somehow removes triple spaces and gives me single spaces and S becomes: "hello my name".
  I tried iterating one by one:</p>
  
  <pre><code>string S = "";
  for (auto it = L.begin(); it!=L.end(); it++){
     S+=*it;
  }
  </code></pre>
  
  <p>I still get "hello my name" with single spaces.
  I tried storing the list in a vector of chars and then turning into a string by looping through vector and pushing back into string one by one and still it ignores multiple spaces. How do I tell the computer to copy the characters of a list to a string verbatim, regardless of how many consecutive whitespace characters there are. Even if it is just a list of spaces, I'd like to get a string of spaces. Any help?</p>
  
  <p>See my code below:</p>
  
  <pre><code>int main() {
      list&lt;char&gt; L {'h', 'e', 'l', 'l', 'o', ' ', ' ', ' ', 'm', 'y', ' ', ' ', ' ', 'n', 'a', 'm', 'e'};
  
      string S_attempt1(L.begin(), L.end());
  
      string S_attempt2 = "";
      for (auto it = L.begin(); it != L.end(); it++){
          S_attempt2+=*it;
      }
  
      cout &lt;&lt; S_attempt1 &lt;&lt; endl;
      cout &lt;&lt; S_attempt2 &lt;&lt; endl;
  }
  </code></pre>
  
  <p>For some the strings I get are <code>"hello my name"</code> instead of <code>"hello   my   name"</code></p>