繁体   English   中英

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

[英]Process returned -1073741819 (0xC0000005) in code::blocks c++

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

我在 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] << " ";

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM