arrays - Vector Subscript out of range in C++ -
i facing problem while loading vector array vector rgb array. after rgbv = pointcloud_rgb[i]; getting error "vector subscript out of range". can guide me please. regards suhas const std::vector<cv::vec3b>& pointcloud_rgb; (unsigned int i=0; i<points.size(); i++) { cv::vec3b rgbv(255,255,255); if (pointcloud_rgb.size() >= i) { rgbv = pointcloud_rgb[i]; } } you have off-by-one error. if pointcloud_rgb.size() == i , i 1 element past end of vector. to fix this, change condition this: if (pointcloud_rgb.size() >= i) { to this: if (pointcloud_rgb.size() > i) {