Getting vector iterator not deferencable for code below, but I don't see why. I am simply iterating through the 2d array and instantiating all values to 0. Where am I iterating to an invalid location?
vector<vector<bool>> isduplicate(100);
for(int i=0;i<isduplicate.size();i++){
for(int s=0;s<isduplicate.size();s++)
isduplicate[i][s]=false;
}
You are iterating over isduplicate
twice. You should iterate over isduplicate[i]
in the inner loop:
vector<vector<bool>> isduplicate(100);
for(int i=0;i<isduplicate.size();i++){
for(int s=0;s<isduplicate[i].size();s++)
isduplicate[i][s]=false;
}
However, isduplicate[i]
is empty for all i
, therefore you won't iterate over anything in the inner loop.
If what you want is to have 100 vectors of 100 bool
s containing the false
value, then:
vector<vector<bool>> isduplicate(100, vector<bool>(100, false));
Should do it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.