问题
Here is the code I have:
string words[n];
.
.
.
for(int j = 0; j < sizeof(words)/sizeof(words[0]); j++){
if(words[j].find(new_word) != std::string::npos){...} //abort(3) called
}
However, SIGABRT isn't called in the same code when I call find on a normal string, like
for(int j = 0; j < sizeof(words)/sizeof(words[0]); j++){
if(s.find(new_word) != std::string::npos){...} //abort(3) NOT called
Why is this behavior happening? Isn't words[j] referring to a string element? Edit: adding the entire code, in case the snippet isn't sufficient :
#include <stdio.h>
#include<string>
#include<stdlib.h>
#include<iostream>
using namespace std;
int main() {
int T;
cin>>T;
while (T--){
int n;
cin>>n;
string words[n];
for(int i =0; i<n;i++){
cin>>words[i];
}
string s;
cin>>s;
str来源:https://stackoverflow.com/questions/46882428/sigabrt-called-when-calling-find-on-a-string-element-in-an-array