如何使用 std::sort 对 std::array 进行排序
How to sort std::array with std::sort?
#include <iostream>
#include <array>
#include <algorithm>
#include <cstring>
using namespace std;
int main() {
array<char, 20> test{"HelloWorld"}, tmp;
// method 1
tmp = test;
sort(tmp.begin(), tmp.begin() + strlen(tmp.begin()));
cout << "result: " << tmp.data() << endl;
// method 2
tmp = test;
sort(tmp.begin(), tmp.end());
cout << "result: " << tmp.data() << endl;
return 0;
}
std::array
可以使用方法 1 进行排序。但它太丑了。
我更喜欢方法 2,但什么都不能返回。怎么了?
第二种方法是将所有