Skip to main content
added 6 characters in body
Source Link
Seth Carnegie
  • 75.3k
  • 22
  • 185
  • 252

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)); 

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 c == c2 && ::isspace(c); }), std::end(text)); 

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) && ::isspace(c2); }), std::end(text)); 
Source Link
Seth Carnegie
  • 75.3k
  • 22
  • 185
  • 252

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 c == c2 && ::isspace(c); }), std::end(text));