视觉对象触发了断点 c++
Visual triggered a breakpoint c++
我是编码新手,我试图写一个刽子手游戏。程序随机选择10个单词中的一个,仅显示"_",每次猜测后屏幕刷新。
问题是有时循环显示的是整个屏幕的 2 倍。所以,我尝试使用——
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
但后来 Visual 告诉我,程序触发了一个断点。怎么了?
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
void showLogo();
int main()
{
int number, amount;
int mistake = 5;
int wrongLetter = 0;
char letter;
char tab[13];
char unknown[13];
char usedLetters[5];
char *wsk;
srand(time(NULL));
number = rand() % 10; //choose one of 10 words
string words[10] ={"LONGITUDINAL","UNFORTUNATELY","EXPLANATORY",
"PERENNIAL","UNPUTDOWNABLE","REMORSELESS",
"INTERMITTENT","ADJUDICATE","INERSTITIAL",
"MALPOSED" };
amount = size(words[number]);
strcpy_s(tab, words[number].c_str()); //string to char
for (int i = 0; i < amount; i++)
{
unknown[i] = '_';
}
while (mistake)
{
int noOfGuessed = 0;
showLogo();
cout << "You have: " << mistake << " chances." << endl << endl;
cout << "Used words: ";
for (int i = 0; i < wrongLetter; i++)
{
cout << usedLetters[i] << " ";
}
cout << endl << endl;
for (int i = 0; i < amount; i++)
{
cout << unknown[i] << " ";
}
cout << "t Enter a letter: ";
letter = getchar();
letter = toupper(letter);
for (int i = 0; i < amount; i++)
{
if (letter == tab[i] && unknown[i] == '_')
{
wsk = &unknown[i];
*wsk = letter;
noOfGuessed++;
}
}
if (noOfGuessed == 0)
{
mistake--;
usedLetters[wrongLetter] = letter;
wrongLetter++;
}
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
system("cls");
}
system("pause");
return 0;
}
void showLogo()
{
cout << "ttttttt HANGMAN" << endl;
cout << endl;
cout << endl;
cout << endl;
}
ignore()
将设置cin的eof位,并使流处于错误状态。调用ignore()
后,应始终清除流错误位。
cin.ignore(std::numeric_limits<std::streamsize>::max(), 'n');
cin.clear();
相关文章:
- 无法删除指针,已触发断点
- 条件断点在不应该触发时触发
- GDB 断点在 Mac 上是不准确的
- 在 vscode 中运行时无法暂停或设置断点
- 不会命中此断点
- 当前不会命中断点。没有调试器目标代码类型的可执行代码与此文件关联
- 如何在进入动态打开的共享库时设置断点?
- 为什么断点显示数组的第二个值是一个大数字?额外学分工作
- 代码在 msvcrt .dll函数上设置断点失败
- 如何在引用上设置数据断点
- 无法在visual studio 2017(本机c++)中禁用数据断点
- 为什么在c++中使用Delete[]会出现跟踪/断点错误
- for循环的条件只有在遇到断点后才生效
- 项目名称.exe 已触发断点
- 视觉对象触发了断点 c++
- 实现在多线程代码中安全恢复的断点
- 如何在 gdb 中的所有构造函数上同时为 C++ 对象设置断点?
- C/C++ 经过的流程周期,不包括断点处
- 在 Visual Studio 2012 中未命中断点
- 无法在 XmlHttpRequest 模块上获取断点(Javascript 引擎/XHR 请求)