2016-08-22 70 views
0

它說:程序有時不能運行,並給了我調試錯誤

調試錯誤!

R6010 -abort()被調用

我真的不知道該怎麼辦纔好。我正在製作一個程序,自動生成SliceThePie的評論,所以你不必花時間想出來。

#include "stdafx.h" 
#include <Windows.h> 
#include <ctime> 
#include <cstdlib> 
#include <iostream> 
#include <stdlib.h> 
#include <string> 
#include <array> 
using namespace std; 

void type_text(const std::string& text) 
{ 
    for (size_t i = 0; i < text.size(); ++i){ 
     cout << text[i] << flush; 

     Sleep(30); 
    } 
} 



int generateAnswers(int loop){ 
    srand(time(NULL)); 
    int firstSentence = rand() % 8 + 0; 
    int descriptors1Sentence2 = rand() % 6 + 0; 
    int secondSentence = rand() % 10 + 0; 
    int descriptors1Sentence = rand() % 6 + 0; 
    int describe1Sentence = rand() % 14 + 0; 
    int punc1C = rand() % 2 + 0; 

    array<int, 6> returning = { firstSentence, descriptors1Sentence2, secondSentence, descriptors1Sentence, describe1Sentence, punc1C }; 

    return returning[loop - 1]; 
} 
void randGen(){ 
    srand(time(NULL)); 

    //cout << rand() % 10 + 1 << endl; 
    string descriptors1[] = { "beat ", "tempo ", "instrumentals ", "synth ", "midi ", "effects "}; 
    string descriptors2[] = { "mix ", "sound ", "volume ", "timing ", "rhythm ", "composure " , "melody ", "chorus "}; 
    string describe1[] = { "amazing", "great", "mediocre", "fair", "average", "fantastic", "beautiful", "A+ worthy", "top notch", "top of the line", "one of the best", "needing work", "not the best", "lackluster" }; 
    string firstSen []= { "Truthfully ", "I believe " , "In my opinion, ", "In my honest opinion, ", "I honestly believe ", "I really think that ", "I think that " , "First off, " }; 
    string secondSen[] = { "In addition to this, ", "Additionally, ", "Also, ", "Furthermore, ", "Continuing, " , "To continue, ", "In addition to my last point, " }; 
    string punc1[] = { ".", "!" }; 

    int firstSentence = generateAnswers(1); 
    int descriptors1Sentence2 = generateAnswers(2); 
    int secondSentence = generateAnswers(3); 
    int descriptors1Sentence = generateAnswers(4); 
    int describe1Sentence = generateAnswers(5); 
    int punc1C = generateAnswers(6); 
    string finFirst = firstSen[firstSentence]; 
    string finDesc2 = descriptors1[descriptors1Sentence2]; 
    string finDesc1 = descriptors1[descriptors1Sentence]; 
    string finDescr1 = describe1[describe1Sentence]; 
    string punc1S = punc1[punc1C]; 
    string finSecond = secondSen[secondSentence]; 
    string Final = finFirst + "the " + finDesc1 + "was " + finDescr1 + punc1S + " " + finSecond + "the " + finDesc2 + "was "; 
    cout << "Waiting for review to complete..." << endl; 
    cout << "\n" << endl; 
    type_text(Final); 
    cout << "\n" << endl; 
    cout << "Review complete." << endl; 

} 

int main() { 
    SetConsoleTitle(TEXT("Diloq v1.01")); 
    randGen(); 
    Sleep(5000); 
    return 0; 
} 

我最初運行到我的電腦沒有足夠的內存來運行偶爾它的問題,但我認爲我已經修復了,因爲它不經常發生了。但是,現在我得到了調試錯誤。

任何幫助將不勝感激!

+3

你應該使用一步步調試器,可找到你的代碼中出現錯誤 – wasthishelpful

回答

0

您有一個出口secondSentence的訪問權限。它的大小是7但你產生隨機數高達9

int secondSentence = rand() % 10 

這可以通過例如進行檢測GCC的消毒:

$ g++ -std=c++11 -fsanitize=undefined -Og -g main.cpp && ./a.out 

main.cpp:55:48: runtime error: index 8 out of bounds for type 'string [7]' 
+0

謝謝!完全解決了我的問題。不再發生:D –

相關問題