Еще одно решение
Использование функции для выполнения работы.
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
constexpr size_t MaxRows = 300;
constexpr size_t MaxColumns = 500;
using MyType = double;
using Columns = std::vector<MyType>;
using Matrix = std::vector<Columns>;
void copySubMatrix( const Matrix& source,Matrix& destination,const size_t& startRow,const size_t& endRow,const size_t& startColumn, const size_t& endColumn)
{
// Clear destination matrix
destination.clear();
// Copy rows end columns
std::for_each(source.begin() + startRow, source.begin() + endRow + 1, [&](const Columns & c) {
Columns row{ c.begin() + startColumn, c.begin() + endColumn + 1};
destination.push_back(row); });
}
int main() {
// Define source matrix with given size and empty destination matrix
Matrix A(MaxRows, Columns(MaxColumns));
Matrix result{};
// Fill source matrix with running values
std::for_each(A.begin(), A.end(), [i = 0](Columns & c) mutable {for (MyType& m : c) m = i++; });
// Copy the given range to the destination matrix
copySubMatrix(A, result, 5, 10, 25, 100);
// Display destination matrix
std::for_each(result.begin(), result.end(), [](const Columns & c) {
std::copy(c.begin(), c.end(), std::ostream_iterator<MyType>(std::cout, " ")); std::cout << "\n"; });
return 0;
}