Check Mat doc for details
BTW, you have to be sure that there is enough space(size and data type) in destination.
Check for data type
if (srcMat.type() != dstMat.type())
return;
for a single row you can use assignment like below (this dstMat.row(5) = srcMat.row(1)
will not work)
if (srcMat.cols == dstMat.cols)
srcMat.row(1).copyTo(dstMat.row(5)); //copy the 2nd row to the 6th row
In general you can use ROI like here
Rect srcRect(Point(0, 1), Size(srcMat.cols, 1)); //select the 2nd row
Rect dstRect(Point(3, 5), srcRect.size() ); //destination in (3,5), size same as srcRect
dstRect = dstRect & Rect(Point(0, 0), dstMat.size()); //intersection to avoid out of range
srcRect = Rect(srcRect.tl(), dstRect.size()); //adjust source size same as safe destination
srcMat(srcRect).copyTo(dstMat(dstRect)); //copy from (0,1) to (3,5) max allowed cols
As alternative you can use rowRange
if (srcMat.cols == dstMat.cols)
srcMat.rowRange(1, 2).copyTo(dstMat.rowRange(5, 6)); //copy row: 2nd->6th
Or more general range
Range colRange = Range(0, min(srcMat.cols, dstMat.cols)); //select maximum allowed cols
//copy the 2nd row to the 6th row max allowed cols
srcMat(Range(1, 2), colRange).copyTo(dstMat(Range(5, 6), colRange));