I am trying to sort arrays (yes, not vectors) of strings, following some suggestions from sites such as this one. This is the code I wrote so far, but it always prints out this long error (which has no results on google). How can this be fixed?
#include <algorithm>
#include <cstring>
#include <iostream>
//qsort(names, n, 15, (int (*)(const void *, const void *))strcmp);
int main()
{
std::cout << "hi";
char arr[3][6];
strcpy(arr[0], "hello"), strcpy(arr[1], "hillo"), strcpy(arr[2], "hallo");
std::sort(arr, arr + 3, [](char const *lhs,
char const *rhs) { return strcmp(lhs, rhs) < 0; });
//qsort(arr, 3, 20, (int (*)(const void *, const void *))strcmp);
for (int i = 0; i < 3; ++i)
std::cout << arr[i] << '\n';
}
const char *arr[] = { "hello", "hillo", "hallo" };and try again. Then consider what changed and why it now works.