请将以下代码转换为C++：


def quick_sort(arr):
if len(arr) < 2:
return arr
else:
pivot = arr[0]
less = [i for i in arr[1:] if i <= pivot]
greater = [i for i in arr[1:] if i > pivot]
return quick_sort(less) + [pivot] + quick_sort(greater)
以下是C++版本的快速排序代码：

```
#include <iostream>
#include <vector>

using namespace std;

vector<int> quick_sort(vector<int> arr) {
    if (arr.size() < 2) {
        return arr;
    } else {
        int pivot = arr[0];
        vector<int> less, greater;
        for (int i = 1; i < arr.size(); i++) {
            if (arr[i] <= pivot) {
                less.push_back(arr[i]);
            } else {
                greater.push_back(arr[i]);
            }
        }
        less = quick_sort(less);
        greater = quick_sort(greater);
        less.push_back(pivot);
        less.insert(less.end(), greater.begin(), greater.end());
        return less;
    }
}

int main() {
    vector<int> arr = {5, 3, 8, 6, 2, 7, 1, 4};
    vector<int> sorted_arr = quick_sort(arr);
    for (int i = 0; i < sorted_arr.size(); i++) {
        cout << sorted_arr[i] << " ";
    }
    cout << endl;
    return 0;
}
```