У меня есть этот код, который имеет два массива. Он сортирует arr [], так что самое высокое значение будет в индексе 0. Теперь второй массив arr1 [] содержит строки, я бы хотел, чтобы код применялся независимо изменения, сделанные в arr [], до arr1 []. Так что arr [0] вернет 6, а arr1 [0] вернет строку "d1" . Обратите внимание, что "d1" имеет тот же индекс, что и 6? После сортировки я хотел бы, чтобы те же значения все еще имели свои строковые копии.
Как мне это сделать?
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std ;
main(){
int arr[ 5 ] = { 4, 1, 3, 6, 2 };
string arr1[ 5 ] = { "a1", "b1", "c1", "d1", "e1" };
std::sort( arr, arr + 5, std::greater< int >() );
cout << arr[0] << arr1[0] << endl;
system("pause");
}