简体   繁体   English

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

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

I have a program that uses getline to populate an array of strings.我有一个使用 getline 填充字符串数组的程序。 When I run this program, it outputs the correct values from the getline(cin) and then the program crashes, issuing the error messege "Process returned -1073741819 (0xC0000005)" I understand that this code has to deal with accessing memory locations.当我运行这个程序时,它从 getline(cin) 输出正确的值,然后程序崩溃,发出错误消息“进程返回 -1073741819 (0xC0000005)”我知道这段代码必须处理访问 memory 位置。 I have tried using pointers, but everything that I have tried has caused the program to crash in the same manner.我尝试过使用指针,但我尝试过的一切都导致程序以同样的方式崩溃。 Can you please provide advice on what I can do to fix this issue?你能否就我能做些什么来解决这个问题提供建议?

I am using Code::Blocks for this program on windows 10我在 windows 10 上为这个程序使用 Code::Blocks

edit: I am putting the strings in an array to be tested for the number of similar words编辑:我将字符串放在一个数组中以测试相似词的数量

    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 is the error code for an assert. 0xC0000005 是断言的错误代码。 Given your code the most likely assert to fire is validation that your array indexing is valid.给定您的代码,最有可能触发的断言是验证您的数组索引是否有效。 As already pointed out in the comments testEmail[wordCount] is out of bounds as C++ arrays are index 0 based the "count" is one past the last valid index.正如评论中已经指出的 testEmail[wordCount] 超出范围,因为 C++ arrays 是索引 0,基于“计数”是最后一个有效索引的一个过去。 The application is likely asserting this is invalid at runtime.应用程序可能会在运行时断言这是无效的。

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

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