函数的另一种写法:
#include<iostream>
#include<string>using namespace std;
void main()
{
auto target = [&](const string &s){return s == "abc";};
string test1 = "abc";
string test2 = "abcd";
cout <<"target(\"abc\") = "<<target(test1)<< endl;
cout << "target(\"abcd\")= " <<target(test2) <<endl;
getchar();
}
(在百度知道上看到的解答,扩充了一下答案的内容,后面继续补充)