它说:
调试错误!
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;
}
我最初遇到的问题是我的计算机没有足够的内存来偶尔运行它,但我认为我已经解决了这个问题,因为它不再经常发生。但是,现在我收到了调试错误。
任何帮助都将不胜感激!!
答案 0 :(得分:0)
您对secondSentence
有界限访问权限。其大小为7
,但您生成的随机数最多为9
:
int secondSentence = rand() % 10
这可以通过例如海湾合作委员会的消毒剂:
$ 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]'