在c++中调试程序时,我得到一个空白屏幕
I get a blank screen when debugging a program in c++
现在发生的是(在编辑代码之后)每当我输入多个单词时,它就会痉挛。修复吗?谢谢。抱歉我看起来好像什么都不知道。昂贵的书,没有人教我,让我在网上阅读教程。(编辑后的代码如下)
#include <iostream>
#include <string>
using namespace std;
string qu;
int y;
int main()
{
y = 1;
while (y == 1)
{
cout << "Welcome to the magic 8-ball application." <<"nAsk a yes or no question, and the 8-ball will answer." << "n";
cin >> qu;
cout << "nProccessing...nProccessing...nProccessing...";
cout << "The answer is...: ";
int ans = (int)(rand() % 6) + 1;
if (ans == 1)
cout << "Probably not.";
if (ans == 2)
cout << "There's a chance.";
if (ans == 3)
cout << "I don't think so.";
if (ans == 4)
cout << "Totally!";
if (ans == 5)
cout << "Not a chance!";
if (ans == 6)
cout << "75% chance.";
system("CLS");
cout << "nWant me to answer another question?" << "(1 = yes, 2 = no.)";
cin >> y;
}
return 0;
}
while (y = 1);
应该 while (y == 1)
您有多余的;
,应该使用==
。
这里有一个无限循环:
while (y = 1);
删除;
。也是y == 1
,不是y = 1
。
为了避免以后出现这些错误:
1)反向比较:
while (1 == y)
现在如果你输入=
而不是==
,那么你的代码不会编译,因为1 = y
无效。
尽管大多数编译器在条件中赋值时会警告你。你不应该忽略编译器的警告。
2)将左括号放在同一行:
while (1 == y) {
// ...... some code
}
现在,如果你在行尾输入;
,那么你的代码仍然是正确的:
while (1 == y) {;
// ...... some code
}
相关文章:
- 如何制作一个只包含字符的简单加载屏幕
- Cout 一个字符串可以打印任何内容到屏幕上
- 它是一个"X",漂浮在输出屏幕上并实时移动
- 直接X 11:在屏幕上绘制一个简单的彩色矩形
- 将25个甚至整数存储到一个名为intlist的整数阵列中,然后在屏幕上显示数组,并在屏幕上显示名为fivintegers
- 从另一个桌面捕获屏幕截图
- 我试图运行OpenGL,但Glut屏幕只是呈现一个白色屏幕
- 我如何在屏幕上打开一个文件c++
- 如何在屏幕上多次复制一个精灵,每个精灵都有相同的代码
- OpenGL,C++,为什么glutReshapeFunc函数给出了一个黑色的OpenGL屏幕
- 如何获得一个循环来在屏幕c++上转换输出
- 如何将顶点位置传递给顶点着色器.我写了一个着色器,它不会在屏幕上绘制任何内容
- GLSL着色:整个屏幕都是彩色的,而不仅仅是一个四边形
- c++linux控制台清除屏幕的一个区域
- MFC PreCreateWindow,用于创建一个填充除任务栏之外的屏幕的窗口
- 如何在一个屏幕中使用两个缓冲区?可能吗?(快板)
- 问如何正确地做一个屏幕保护程序的功能窗口C++
- 从Qt快速控件加载下一个屏幕/应用程序窗口
- 触摸屏双击直接跳转到下一个屏幕
- 我如何使用一个屏幕外的DC渲染位图的编译一次