I am doing a leetcode problem, I have a vector of vector of strings i.e vector< vector<string> > group;
I want to perform some specific task when any of the strings in the group vector is empty i.e of value equal to ""
. But when I try to make the comparison with std::string::compare()
method, I get the following error.
Line 1117: Char 34: runtime error: applying non-zero offset 781176 to null pointer (stl_vector.h)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/stl_vector.h:1126:34
But when I run the same program in Online C++ compiler, it works fine.
The piece of code that gives the error is as below,
for(int k=0; k<groups.size(); k++){
if(!groups[k][0].compare("")){
index = k;
break;
}
}
I spent around an hour trying to fix this, If anyone could help, I would appreciate it. Thanks 🙂