title: Best way to remove white spaces from std::string
body: <p>I have loaded a text file content to a std::string. And I want to remove the whitespaces from the loaded string. </p>
  
  <ol>
  <li>Which below method need to be used for better performance?    </li>
  <li>Which below method can be a best practice.?   </li>
  <li>Else any better way is there to achieve this?   </li>
  </ol>
  
  <p><strong>Method 1:</strong><br>
  Scan the string using string.find() in a loop statement and remove whitespace using string.erase();</p>
  
  <p><strong>Method 2:</strong><br>
  Scan the string using string.find() in a loop statement and copy the non whitespace characters to a new string() variable using string.append();</p>
  
  <p><strong>Method 3:</strong><br>
  Scan the string using string.find() in a loop statement and copy the non whitespace characters to a new string(size_t n, char c) variable using string.replace();</p>
  
  <p><strong>Method 4:</strong><br>
  Allocate a char* (using malloc[size of the source string])<br>
  Scan the string using string.find() in a loop statement and copy the non whitespace characters to the char* variable using strcpy and then strcat();<br>
  finally copy the char* to a new string<br>
  free char*    </p>