C++ 向量构造中的访问冲突 #包括 std::向量v[1000]; int main() { 返回0; }

C++ 向量构造中的访问冲突 #包括 std::向量v[1000]; int main() { 返回0; },c++,stl,window,console-application,visual-studio-2019,C++,Stl,Window,Console Application,Visual Studio 2019,我刚刚在VisualStudio2019中使用了这段代码 #include <vector> std::vector<int> v[1000]; int main() { return 0; } Project1.exe__CheckForDebuggerJustMyCode()未知 >Project1.exe!STD::Exchange(STD::YuleCulePrxult*yVal& & NexYVAL)599 C++ Project1.exe!STD

我刚刚在VisualStudio2019中使用了这段代码

#include <vector>

std::vector<int> v[1000];

int main()
{
    return 0;
}
Project1.exe__CheckForDebuggerJustMyCode()未知
>Project1.exe!STD::Exchange(STD::YuleCulePrxult*yVal& & NexYVAL)599 C++
Project1.exe!STD::向量::~(676)C++
Project1.exe`EH向量析构函数迭代器(Valu**PTR,未签名的γ-In64大小,未签名的γ-In 64计数,空隙(*)(空洞*)析构函数)C++
Project1.exe`“v”()C++动态析构函数析构函数
ucrtbased.dll!00007ffbdf8e48d7()未知
ucrtbased.dll!00007ffbdf8e42e5()未知
ucrtbased.dll!00007ffbdf8e441a()未知
ucrtbased.dll!00007ffbdf8e4a81()未知
ucrtbased.dll!00007ffbdf8e3c51()未知
ucrtbased.dll!00007ffbdf8e3afd()未知
ucrtbased.dll!00007ffbdf8e3b6a()未知
ucrtbased.dll!00007ffbdf8e3de4()未知
ucrtbased.dll!00007ffbdf8e4176()未知
Project1.exe__ScTr.CuiMuxMnIsHeSEH()297行C++
Project1.exe__C++ 331行
Project1.exe!(17)C++
内核32.dll!00007ffc168c7034()未知
ntdll.dll!00007ffc1829cec1()未知
0x00007FF6087210D2上的访问冲突。 这是一个调用堆栈

为什么这段代码会崩溃?我试图安装另一个版本的visual studio(2017),但它仍然崩溃。 我也尝试过重新安装windowsdk,但它不起作用

可能的原因是什么,如何解决


第二个代码示例:

    Project1.exe!__CheckForDebuggerJustMyCode() Unknown
>   Project1.exe!std::exchange<std::_Container_proxy *,std::nullptr_t>(std::_Container_proxy * & _Val, void * && _New_val) Line 599 C++
    Project1.exe!std::vector<int,std::allocator<int>>::~vector<int,std::allocator<int>>() Line 676  C++
    Project1.exe!`eh vector destructor iterator'(void * ptr, unsigned __int64 size, unsigned __int64 count, void(*)(void *) destructor) C++
    Project1.exe!`dynamic atexit destructor for 'v''()  C++
    ucrtbased.dll!00007ffbdf8e48d7()    Unknown
    ucrtbased.dll!00007ffbdf8e42e5()    Unknown
    ucrtbased.dll!00007ffbdf8e441a()    Unknown
    ucrtbased.dll!00007ffbdf8e4a81()    Unknown
    ucrtbased.dll!00007ffbdf8e3c51()    Unknown
    ucrtbased.dll!00007ffbdf8e3afd()    Unknown
    ucrtbased.dll!00007ffbdf8e3b6a()    Unknown
    ucrtbased.dll!00007ffbdf8e3de4()    Unknown
    ucrtbased.dll!00007ffbdf8e4176()    Unknown
    Project1.exe!__scrt_common_main_seh() Line 297  C++
    Project1.exe!__scrt_common_main() Line 331  C++
    Project1.exe!mainCRTStartup() Line 17   C++
    kernel32.dll!00007ffc168c7034() Unknown
    ntdll.dll!00007ffc1829cec1()    Unknown
#包括
#包括
int main()
{
printf(“之前”);
std::向量v(3000);
printf(“在\n之后”);
返回0;
}
每次运行时,异常都会更改。上述代码的调用堆栈之一是:

#include <stdio.h>
#include <vector>

int main()
{
    printf("before\n");
    std::vector<std::vector<int>> v(3000);
    printf("after\n");
    return 0;
}
ConsoleApplication2.exe!std::vector::_Getal(void)未知
ConsoleApplication2.exe!STD::向量::向量()446行C++
ConsoleApplication2.exe!STD::OutEndotTalpLoalAtter特性::构造(STD:分配器和α形式,STD::向量*constαPTR)695线C++
ConsoleApplication2.exe!STD::YunNealAldieZ.ButoOutAual::C++ EMPACTION()(1509)C++
ConsoleApplication2.exe!STD::In unIZALIZEDIVALYEXGROUTTIN(STD:Vector **第一,未签名的In 64 64计数,STD::分配器和)1835 C++
ConsoleApplication2.exe!STD::向量::uuSube(STD::向量*,const un签署,i64 64计数,STD::YoValueIIITyTAG,正式)1584行C++
ConsoleApplication2.exe!STD::向量::C++构造No.CopIIICOSIFOSY(const un签署α,i64 64计数,const STD::YoValueIIITyTAG和YAVA)462行C++
ConsoleApplication2.exe!STD::向量:向量(const un签署,i64 64,伯特::分配器和)473线C++
>ConsoleApplication2.exe!第8行C++

+

此代码也会崩溃

    ConsoleApplication2.exe!std::vector<int,class std::allocator<int> >::_Getal(void)   Unknown
    ConsoleApplication2.exe!std::vector<int,std::allocator<int>>::vector<int,std::allocator<int>>() Line 446    C++
    ConsoleApplication2.exe!std::_Default_allocator_traits<std::allocator<std::vector<int,std::allocator<int>>>>::construct<std::vector<int,std::allocator<int>>>(std::allocator<std::vector<int,std::allocator<int>>> & __formal, std::vector<int,std::allocator<int>> * const _Ptr) Line 695  C++
    ConsoleApplication2.exe!std::_Uninitialized_backout_al<std::allocator<std::vector<int,std::allocator<int>>>>::_Emplace_back<>() Line 1509   C++
    ConsoleApplication2.exe!std::_Uninitialized_value_construct_n<std::allocator<std::vector<int,std::allocator<int>>>>(std::vector<int,std::allocator<int>> * _First, unsigned __int64 _Count, std::allocator<std::vector<int,std::allocator<int>>> & _Al) Line 1835   C++
    ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::_Ufill(std::vector<int,std::allocator<int>> * _Dest, const unsigned __int64 _Count, std::_Value_init_tag __formal) Line 1584    C++
    ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::_Construct_n_copies_of_ty<std::_Value_init_tag>(const unsigned __int64 _Count, const std::_Value_init_tag & _Val) Line 462  C++
    ConsoleApplication2.exe!std::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>::vector<std::vector<int,std::allocator<int>>,std::allocator<std::vector<int,std::allocator<int>>>>(const unsigned __int64 _Count, const std::allocator<std::vector<int,std::allocator<int>>> & _Al) Line 473 C++
>   ConsoleApplication2.exe!main() Line 8   C++
#包括
int main()
{
自动a=新标准::向量[3000];
删除[]a;
返回0;
}
#包括
int main()
{
自动a=新标准::字符串[3000];
删除[]a;
返回0;
}
所以我怀疑内存不足,不过下面的代码运行良好

#include <string>

int main()
{
    auto a = new std::string[3000];
    delete[] a;
    return 0;
}
#包括
int main()
{
自动a=新整数[10000000];
删除[]a;
返回0;
}

我已尝试卸载visual studio安装程序中的所有visual studio和Windows工具包,并重新安装了它们,但是,仍然会发生这种情况。

我在visual studio 2019中测试了您的程序,因为这就是您正在使用的程序

#include <vector>

int main()
{
    auto a = new int[10000000];
    delete[] a;
    return 0;
}
#包括
std::向量v[1000];
int main()
{
返回0;
}
它很好用。但你已经知道了。我在64位模式下使用它。(你也这样做了)

因为它在使用“std::”时崩溃,所以我检查了在使用std和不使用std时加载的DLL。您应该检查DLL中的差异。 无性病:

有性病:

我不确定这是否真的是一个软件问题。(因为您提到您使用visual studio 2017进行了测试,但它仍然崩溃)
在这种情况下,我认为这是一个问题与您的RAM。也许你可以在另一台计算机上测试你的代码。

可能与你的错误无关,但是
std::vector v[1000]正在声明一个包含1000个向量的数组。你的意思是
std::vectorv(1000)?显示的代码没有问题,这显然是未知的安装或编译器或运行库的损坏问题。我没有任何机会重现这种行为。它看起来像是破坏时崩溃,而不是“v”的构造-
动态atexit析构函数-
,但是,看起来可能是某种VS错误。@GimunEom
std::vector v(1000)是不正确的代码,因为第二维度向量也必须初始化。正确的代码应该是
std::vector v(3000,std::vector(3))#include <vector>

int main()
{
    auto a = new int[10000000];
    delete[] a;
    return 0;
}
#include <vector>

std::vector<int> v[1000];

int main()
{
    return 0;
}