我有一个我想要sort
的字符数组。问题是我是否将数组原样传递给sort
函数,而不是实际转换数组字符,而这些字符实际上是ASCII等价数字。对于例如4成为52。
std::vector<int> classStudents;
....
char* cend = cAllowedStudents+maxAllowedStudents;
std::sort(cAllowedStudents, cend);
std::set_difference(classStudents.begin(), classStudents.end(),cAllowedStudents, cend,std::back_inserter(diff));
我也尝试通过这个将整个数组转换为单独的int
数组(但理想情况下我不想使用另一个数组,而只是作为最后一个选择):
iAllowedStudents[i]=(int)cAllowedStudents[i];
但它也是一样的,所以如何将此cAllowedStudents
转换为与std::set_difference
一起使用
答案 0 :(得分:1)
使用:
template< class RandomIt, class Compare >
void sort( RandomIt first, RandomIt last, Compare comp );
并传递自定义比较函数