程序运行时出现空白窗口
Blank Window while program is running?
//***********************************************************
#include <iostream>
#include <iomanip>
#include <cstdlib>
// function prototypes
void intOutput();
void floatingPointOutput();
void intMathOperations(int rows, int b, int width); // int math demonstration
void writeHeaderLine(int width);
void writeMathLine(int a, int b, int width);
using namespace std;
int main()
{
int a, b, width, rows;
cout << "nProject 1: Math and Functions";
cout << "n";
cout << "n";
cout << "nProject 1 Start.";
cout << "nZack Cunningham";
cout << "n";
cout << "nInteger Output Demo:";
cout << "n";
intOutput();
floatingPointOutput();
intMathOperations(rows, b, width); // int math demonstration
writeHeaderLine(width);
writeMathLine(a, b, width);
cout << "n";
cout << "nProject 1 End.";
cout << "n";
const int FIELD_WIDTH = 10;
intMathOperations(12, 5, FIELD_WIDTH);
return EXIT_SUCCESS;
}
void intMathOperations(int rows, int b, int width){
cout << "n";
cout << "nInteger Math Operations Demo:";
cout << "n";
writeHeaderLine(width);
cout << "n";
for (int a = 0; a < rows; ++a){writeMathLine(a, b, width);
}
}
void writeHeaderLine(int width){
cout << "n";
cout << setw(width) << "a";
cout << setw(width) << "b";
cout << setw(width) << "a * b";
cout << setw(width) << "a / b";
cout << setw(width)<< "a % b";
}
void writeMathLine(int a, int b, int width){
cout << setw(width) << a;
int rows;
for (int a = 0; a < rows; ++a){writeMathLine(a, b, width);
}
}
void floatingPointOutput(){
double a = 2000;
double b = 3;
double c = a / b;
cout << "n" << a << " / " << b << " = ";
cout << "n" << c;
cout << setprecision(10);
cout << "n" << setw(20) << c;
cout << scientific; // scientific notation
cout << "n" << setw(20) << c;
cout << fixed; // standard decimal notation
cout << "n" << setw(20)<< c;
cout << left; // left justify
cout << "n" << setw(20) << c;
cout << right;
// right justify (default)
cout << "n" << setw(20) << c;
cout << setprecision(6); // return to default
cout << "n" << setw(20) << c;
cout << "n";
}
// function calls
void intOutput(){
cout << "nInteger Output Demo:";
cout << "n";
int a = 12;
int b = 12345678;
cout << "n....5...10...15...20"; // spacing info
cout << "n";
cout << "n" << setw(20) << a;
cout << "n" << setw(20) << b;
cout << "n";
cout << "n" << setw(4) << a;
cout << "n" << setw(4) << b;
cout << left; // left justified
cout << "n";
cout << "n" << setw(20) << a;
cout << "n" << setw(20) << b;
cout << right; // right (default) justified
cout << "n";
}
这是我的程序的所有代码,我已经一遍又一遍地工作了。最后没有错误,但它是一个空白程序,只是在无限循环中运行。我不确定该怎么做,如果有人能帮忙,我将不胜感激。谢谢。
至少你需要解决这个问题。您将变量rows
定义为
int a, b, width, rows;
但是您没有初始化rows
而是在这里使用它,
intMathOperations(rows, b, width); // int math demonstration
它使用for
循环中的rows
作为结束条件。 这是一个问题。
要解决此问题,我建议您打开所有这样的警告
g++ -Wall your_code.cpp
并确保您了解您的每个警告并修复必要的警告。
相关文章:
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 无法通过空白将文本文件行分隔为矢量
- 问:如何使用C++中的按钮从窗口打开窗口
- SDL 窗口不会弹出
- Gtkmm 窗口为空白,不显示任何小部件或标题
- 我的QT程序显示带有标题的空白窗口
- QT子类UI表单显示一个空白窗口
- SDL 窗口弹出,但它是空白的,完全没有响应
- 输入层类型:图像数据在窗口咖啡cpp中给出空白输出
- QT 4.7-在OS X 10.12下,工具提示和Qcombobox弹出窗口空白
- 带有 gtkmm 派生小部件的空白窗口
- 将QT QML应用程序部署到Windows上显示了一个空白窗口
- GLUT显示空白窗口
- 程序运行时出现空白窗口
- 从代码::块运行程序时,控制台窗口为空白
- Gtk::Window set_visible导致一个空白窗口
- 记住创建空白win32窗口的所有内容很重要吗?
- 尝试在打开的总账中创建空白窗口时出现异常输出
- Qt Maps (QML)应用程序窗口是空白的
- 空白窗口