Segmentation Fault (SIGSEGV) when getting data as input in the vector of struct

前端 未结 2 1864
旧时难觅i
旧时难觅i 2021-01-28 01:32

Segmentation Fault (SIGSEGV). Link to code The code gives Segmentation fault error due to the input taken to store the values for vector of struct.

#include<         


        
2条回答
  •  感情败类
    2021-01-28 02:31

    Here is the code that works. I specify the size of the vector when I construct it.

        vector v(n);
    

    Compile code:

    #include
    using namespace std;
    struct s{
        int a;
        int d;
    };
    
    int main(){
            int n;
            cin>>n;
            vector v(n);
            for(int i=0;i>v[i].a;
            }
            for(int i=0;i>v[i].d;
            }
        return 0;
    }
    

提交回复
热议问题