remove whitespace in cpp

#include <iostream>
#include <algorithm>

int main() {
    std::string inputString, outputString;

    // Step 1: Read input string
    std::cout << "Enter a string with whitespace: ";
    std::getline(std::cin, inputString);

    // Step 2: Remove whitespace using std::remove_if and std::isspace
    outputString.resize(inputString.size());
    auto end = std::remove_if(inputString.begin(), inputString.end(), ::isspace);

    // Step 3: Resize the output string to the new size after removal
    outputString.resize(std::distance(inputString.begin(), end));

    // Step 4: Display the result
    std::cout << "String with whitespace removed: " << outputString << std::endl;

    return 0;
}