Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • It will not solve his problem. test also contains '\t' which is not equal to ' '. Commented Feb 19, 2012 at 16:25
  • Won't this also do things like "letting" -> "leting" and skip over ` \t` pairs? Commented Feb 19, 2012 at 16:26
  • Whoops fixed it again, previously it wouldn't combine, for instance, a space and a tab next to each other, but now it does. Commented Feb 19, 2012 at 16:34
  • 2
    Doesn't this result in "a\tvery ugly string" for the sample input, which is wrong? You could add a pass of transform (or maybe a boost::transform_iterator?) to replace all whitespace with space characters, but sometimes it's OK to give up and write a loop ;-) Commented Feb 19, 2012 at 18:43
  • 2
    Why std::remove? You need std::replace_if after std::unique to replace \t characters with ' ' and it still wouldn't remove the leading and trailing whitespaces. This answer doesn't do what the OP asked. Commented Nov 28, 2018 at 12:58