C++ How To Remove Whitespace from a String
Remove Whitespace from a String
Use the isspace() function to skip all whitespace characters:
Example
string text = " Hello World ";
string result = "";
for (char c : text) {
if (!isspace(c)) {
result += c;
}
}
cout << result;
Explanation:isspace() returns true for spaces, tabs and newlines.
Only the characters that are not whitespace are added to result.