gpt4 book ai didi

c++ - 在 C++ 中使用集合 vector 时出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 15:32:19 25 4
gpt4 key购买 nike

#include<iostream>
#include<vector>
#include<bits/stdc++.h>
using namespace std;

int main(){
vector< set< int > > A;
A[0].insert(1);
A[0].insert(2);
}

当我在 Codeblocks 上运行以上 ode 时,出现段错误。任何人都可以回答为什么我会收到此错误以及避免此代码中出现段错误的解决方案。

最佳答案

因为 A 是一个空 vector ,所以 A[0] 不引用有效对象。所以你不应该在上面调用 insert

关于c++ - 在 C++ 中使用集合 vector 时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47544735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com