#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iterator>
constexpr int N = 10;
int main() {
std::vector<int> even;
std::vector<int> odd;
even.resize(N);
// Fill up the 'even' vector with integers starting from from 1 through 'N'
std::iota(even.begin(), even.end(), 1);
// Segregate the odd and even integers from each other
for (auto it = even.begin(); it != even.end(); ++it)
if (*it % 2 != 0) {
// If the number is odd, put it in the 'odd' vector
odd.push_back(*it);
// Remove the number from the even vector
even.erase(it);
}
// Print the result
std::cout << "Even numbers: ";
std::copy(even.begin(), even.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << "\nOdd numbers: ";
std::copy(odd.begin(), odd.end(), std::ostream_iterator<int>(std::cout, " "));
std::cout << '\n';
}
Seems fine to me... C++ couldn't possibly be THAT evil to introduce another nuanced and verbose complexity in there, right?