程序有时无法运行并给我调试错误
Program sometimes doesn't run and gives me debug error
上面写着:
调试错误!
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;
}
我最初遇到的问题是我的电脑没有足够的内存来偶尔运行它,但我想我已经解决了这个问题,因为它不再经常发生了。现在,但是,我得到调试错误。
任何帮助将不胜感激!!
您有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]'
相关文章:
- C++为什么我的编译器成功了,但我的计算机给出了调试错误?
- 分段错误 .AnsiStringToUnicodeString 作为第一个调试错误行.杜比奥斯类等级制度
- 尝试在我的基类中启动线程时,Visual Studio 由于调试错误而中止我的程序
- OpenGL 调试 错误回调函数的 ID 参数是什么?
- 如何调试错误代码 77:cudaErrorIllegal地址当 cuda-memcheck 没有发现问题时
- 如何调试错误消息"abort() has been called"?
- Eclipse调试错误:没有此类文件或目录 n
- 调试错误,在C++中检测到堆损坏
- Qt:如何在QByteArray中调试错误的分配异常
- 尝试运行程序时会收到调试错误
- C 高分列表调试错误
- 我的C++函数不断收到调试错误。我不确定我做错了什么
- 使用 GDB 在 main() 之前调试错误
- c++中的调试错误
- 多线程效率低下:调试错误共享
- 调试错误.已调用R6010中止()
- C++的调试错误真的很令人沮丧
- SDL 项目的调试错误"没有可用于 main() 的源代码"
- 调试错误R6010-已调用abort()
- 程序在Visual Studio Community 2015中执行后,它会显示调试错误