What the best way to replace multiple characters in a string with one char?
string str("1 1 1");
//out: 1 1 1
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This will work on more than just the spaces though. For example, the string “aaabbbcccddd” would become “abcd”. Is that what you want? If you just want to reduce the spaces to one space, you can pass a binary predicate as a third argument to
std::unique, like this one: