What does the mean [](unsigned char x)
Here is my code:
#include <algorithm>
std::string str1 = "Text with some spaces";
str1.erase(std::remove(str1.begin(), str1.end(), ' '), str1.end());
std::cout << str1 << '\n';
std::string str2 = "Text\n with\tsome \t whitesspaces\n\n";
str2.erase(std::remove_if(str2.begin(), str2.end(), [](unsigned char x) {return std::isspace(x);}), str2.end());
std::cout << str2 <<'\n';
答案 0 :(得分:0)
It's the beginning of a lambda function defintion:
[](unsigned char x) {
return std::isspace(x);
}
This defines a temporary function receiving a unsigned char
and returning an int
(automatically determined by the return value of std::isspace
, since the lambda did not specify a return type).