簡體   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