Visual Studio 2015 遇到断点
Visual studio 2015 hitting breakpoint
当我运行代码时,我得到了消息Scattegories.exe has triggered a breakpoint.
它发生在我将第 12 个 nuber 输入我的数组后,但数组仍然有一个"点"。还有一个线程,所以也许就是这样,但它似乎工作正常。所以我不知道它是什么,谢谢。
// A program to keep track of points and time and to give a random letter for the game scattergories
#include<iostream>
#include<ctime>
#include<string>
#include <chrono>
#include <thread>
using std::cout;
using std::cin;
using std::string;
using std::getline;
using namespace std::chrono_literals;
using std::this_thread::sleep_for;
void ltr() //gives a random letter
{
char letter;
letter = rand() % 26 + 65; //assigns a random letter in ascii code to a char (resulting in a random letter)
cout << "The letter is " << letter << "n";
}
void timer()
{
cout << "You got 1.5 minutes to finishn"; //Changing the duration of the timer is done by changing the value of 'i' in the "for" loop
for (int i = 10; i > 0; i--)
{
sleep_for(1s);
}
cout << "DING DONG!!! DING DONG!!! Time's up!!!n";
}
void table(int plr)
{
string ctr[12] = { "A cuntry", "A city", "An animal", "A plant", "A object", "A name", "Food", "Drink", "A game", "A movie", "A book", "A famous person" };
string lst[6][12]; //first dimantion: how many players. second dimantion: how many catagories, third dimantion(if added) will be the round
cin.ignore(); //To avoid the "getline" reading the last input
for (int x = 0; x<plr; x++) //the player changes only after the previus player finishes
{
std::thread t1(timer); //gives time to write the words. Optimaly it would run in the background while each player writes the words.
for (int i = 0; i<12; i++) //changing catagory
{
cout << ctr[i] << ": ";
getline(cin, lst[x][i]);
}
system("cls");
cout << "Next playern";
}
for (int x = 0; x<plr; x++) //this part (the whole "for" loop) is for confirming evreything is writen down
{
cout << "Player number " << x + 1 << ": ";
for (int i = 0; i<12; i++)
{
cout << lst[x][i] << " ";
}
cout << "n";
}
sleep_for(5s);
}
int points() //points gained per round
{
int a, b, c, sum;
cout << "How many sections only you got?n"; //worth 15 points
cin >> a;
cout << "How many words only you got?n"; //worth 10 points
cin >> b;
cout << "How many words you and another person got?n"; //worth 5 points
cin >> c;
sum = a * 15 + b * 10 + c * 5;
return sum; //Note: It doesn't matter how many sections there are.
}
int act() //running the program
{
int Players, Points[6];
cout << "How many people are playing? (Up to six players)";
cin >> Players;
ltr();
table(Players);
//Points = points();
cout << "You have earned " << Points << " this roundnn";
return 1;
}
int main()
{
auto start = std::chrono::high_resolution_clock::now();
srand(time(NULL)); //gives a differant pattern of letters every time
int Points;
Points = act();
for (;;) //inf loop
{
int ph;
cout << "Press 1 to continue or anything else to stopn";
cin >> ph;
if (ph == 1)
{
Points += act(); //keeping score of the rounds
}
else
{
auto end = std::chrono::high_resolution_clock::now();
break;
}
}
cout << "You have earned a total of " << Points << " great job!";
sleep_for(5s); //time to read the last text
return 0;
}
/*
To do list:
-Convert to arduino
-Make timer work in background of of table
-Check if words in the table (for differant players) are the same and give points accordingly
-Check if words are actual words (connect an online dictonary?)
-Make interface? (if possible and I have time to learn how)
-Think of what to do with Hardwear
-Comment rest of the code
*/
std::thread::~thread 这样说:
如果 *this 有一个关联的线程 (joinable() == true),则调用 std::terminate()。
如果您曾经销毁可加入的std::thread
,则调用std::terminate()
。Visual Studio善意地中断std::terminate()
,以便您检查出了什么问题。在void table(int plr)
中,您创建了一个带有std::thread t1(timer);
的线程,但您永远不会加入或脱离它。
为了解决这个问题,你的timer
方法应该更改为在玩家完成回合后立即返回,然后主线程应该加入它。
相关文章:
- 编译包含字符串的代码时遇到问题
- 遇到新行时,有没有办法停止istream_iterator
- 无法删除指针,已触发断点
- 在使用GPU支持编译Tensorflow时,会遇到CUDA_TOOLKIT_PATH未绑定变量
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 条件断点在不应该触发时触发
- 在 for 循环中查找问题时遇到困难
- 创建结构的数组时遇到分段错误
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 为什么我遇到分段错误?
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- 为什么我在尝试模板时遇到视觉工作室C++错误
- 如何从文本文件中读取数值,直到遇到字符类型?
- 从其他类访问类时遇到问题
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- for循环的条件只有在遇到断点后才生效
- 调用 ReadFile 程序后,在 debug_heap.cpp 中遇到断点
- Visual Studio 2015 遇到断点
- 我在这个c ++程序中遇到断点错误,看看.编译器Visual C++ 2010