I am a beginner C++ programmer.
I have this array declared somewhere:
char* patterns[10000];
And a C++ String as input to a function. I am then extracting out all substrings of length 20 (overlapping). I am converting them to C style strings for performance.
for(int i = 0; i<=input.length()-20;i++){
patterns[i] = strdup(input.substr(i,20).c_str());
count = i;
}
However, I get the following error
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr
The odd thing is, even when the I use (1,20) as constant arguments for substr, the error still shows up at some point during the loop. Furthermore, simply printing the substring in a loop is fine. Something must be occurring with either strdup or the assignment to the array, but I don't know what could be happening.
Aucun commentaire:
Enregistrer un commentaire