c++ - using boost::lambda_ to compress whitespaces in a string -
I am using Boost :: Lambda to remove white space later in a string, leaving only one location . I tried this program
#include & lt; Algorithm & gt; # Include & lt; Iostream & gt; #include & lt; String & gt; #include & lt; Boost / lambda / lambda.hpp & gt; Int main () {std :: string s = "str str st st sss"; //s.erase (std :: unique (s.begin (), s.end (), (boost: lambda :: _ 1 == '') & amp; amp; amp; amp; amp; : Lambda :: _ 2 == '')), sand (); /// & LT; Works s.erase (std :: unique (s.begin (), s.end (), (boost :: lambda :: _ 1 == boost :: lambda :: _ 2 == '')), S.end ()); /// & LT; Std :: cout & lt; & Lt; S & lt; & Lt; Std :: endl; Return 0; }
The commented row works fine, but not unsettled.
How to
(boost: lambda :: _ 1 == boost: lambda :: _ 2 == '')
Separately
(boost: lambda :: _ 1 == '') & amp; Amp; (Promotion: lambda :: _ 2 == ''))
The comment in the above program has given me a warning that "Warning C4805: '==': the type of insecure mix 'Bull' and type 'const char' in operation "
Thanks.
in C and C ++ A == B == X (A == X) Is different & amp; Amp; (B == x), the former is interpreted as (a == b) == x, which compares with B and the result of that comparison (true or false) is compared to x is. In your case X is a space character, and uses ASCII in a specific implementation, its code is equal to 32, it compares to the Boolean value which is converted to 0 or 1 is always false.
Comments
Post a Comment