我在线复制了此代码。它是关于排序大的数字:比较std :: sort()中的内联函数
int n;
cin >> n;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
std::sort(a.begin(), a.end(),
[](const string &left, const string &right)
{
if (left.size() != right.size())
{
return left.size() < right.size();
}
else
{
return left < right;
}
});
for (const string &s : a) {
cout << s << '\n';
}
有人可以用文字解释这些行:
[](const string &left, const string &right)
和
for (const string &s : a)
我从来没有遇到过的图书馆,以及一个像循环使用的代码。 谢谢!
[第一次](https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11/7627218#7627218),[second](https://stackoverflow.com/问题/ 15927033/what-is-correct-way-of-using-c11s-range-based-for) –