进程在 code::blocks c++ 中返回 -1073741819 (0xC0000005)

Posted

技术标签:

【中文标题】进程在 code::blocks c++ 中返回 -1073741819 (0xC0000005)【英文标题】:Process returned -1073741819 (0xC0000005) in code::blocks c++ 【发布时间】:2020-04-26 19:25:23 【问题描述】:

我有一个使用 getline 填充字符串数组的程序。当我运行这个程序时,它从 getline(cin) 输出正确的值,然后程序崩溃,发出错误消息 “进程返回 -1073741819 (0xC0000005)” 我知道这段代码必须处理访问内存位置。我尝试过使用指针,但我尝试过的一切都导致程序以同样的方式崩溃。 您能否就我能做些什么来解决这个问题提供建议?

我在 Windows 10 上为这个程序使用 Code::Blocks

编辑:我将字符串放在一个数组中以测试相似词的数量

    int wordCount = 0;
    cout << "Enter the number of words in your email: ";
    cin >> wordCount; //size of array determined by wordCount, which is retrieved from the user
    string testEmail[wordCount] =  ; // declaring and initializing the array
    cout << "Enter the email you wish to test: ";
    getline(cin >> std::ws, testEmail[wordCount]); // this will populate the array from user input
    cout << "The email that will be tested is: ";
    for(int i=0; i<wordCount; i++) // for loop used for testing
        cout << testEmail[i] << " ";

【问题讨论】:

请提供minimal reproducible example。 您希望getline(cin &gt;&gt; std::ws, testEmail[wordCount]); 做什么?与your Rubber Duck讨论这个。 代码块的使用(或不使用)与问题无关。 Getline 会从用户那里得到输入。当它检测到空格时,它会将单词作为字符串存储在数组中。它会为其余的输入做到这一点。我从未使用 getline 填充数组,我不确定使用字符串执行此操作并在空白处创建新条目的属性。 getline 不是这样工作的。该行丢弃前导空格,然后将一行读入超出范围的testEmail[wordCount]。在不知道自己在做什么并希望它有效的情况下,您无法通过将东西放在一起进行编程。通过good book 之类的方式彻底学习该语言。 【参考方案1】:

0xC0000005 是断言的错误代码。给定您的代码,最有可能触发的断言是验证您的数组索引是否有效。正如在 cmets testEmail[wordCount] 中已经指出的那样,因为 C++ 数组的索引为 0,所以“计数”超出了最后一个有效索引。应用程序可能会在运行时断言这是无效的。

【讨论】:

以上是关于进程在 code::blocks c++ 中返回 -1073741819 (0xC0000005)的主要内容,如果未能解决你的问题,请参考以下文章

Code::Blocks C++ 使用 MacOS Mojave 编译:致命错误:sys/cdefs.h:没有这样的文件或目录

如何用Code Blocks创建C++控制台项目

c++零基础的自修课 01-开发工具的安装(code::blocks)

Code::Blockswindows 环境下编译 Code::Blocks(已修正)

Code::Blocks编译不了C++,要怎么样设置编译器?

c++ vector 排序 sort 用不起来 我用的是code::blocks