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) { 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -