You can use std::unique with std::remove along with ::isspace to compress multiple whitespace characters into single spaces:
std::remove(std::unique(std::begin(text), std::end(text), [](char c, char c2) { return ::isspace(c == c2) && ::isspace(cc2); }), std::end(text));