C ++ standard library deleted in a string of characters, such as spaces

See: https: //zh.cppreference.com/w/cpp/algorithm/remove

 

Use the erase and remove fit.

#include <algorithm>
#include <string>
#include <iostream>
#include <cctype>
 
int main()
{
    std::string str1 = "Text with some   spaces";
    str1.erase(std::remove(str1.begin(), str1.end(), ' '),
               str1.end());
    std::cout << str1 << '\n';
}

The output is:

Textwithsomespaces

 

Guess you like

Origin www.cnblogs.com/alexYuin/p/11546159.html