SIGABRT called when calling find() on a string element in an array [closed]

蓝咒 提交于 2019-12-13 09:45:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!