下面是我的代码的一部分(使用构造函数)。在这里,当我运行代码时,scanf 之前的 printf 没有出现。我得到一个空白屏幕,我必须在其中输入否,然后显示 printf 结果。有人可以帮我吗?我需要显示“输入点数”,以便我可以了解我正在输入的条目
Discret::Discret()
{
rich = 0;
solve = 0;
total = 0;
int no;
double no;
printf("\n\n");
printf("==============================================================\n");
printf("Input:\n");
printf("Enter the number of points" );
scanf("%d",&no);
printf("==============================================================\n");
/************************************
*
* Material
*
************************************/
double youngs, poisson;
S = 1000;
P = 0.0;
material.resize(1);
material[0] = new Material(youngs, poisson);
}
最佳答案
printf
适用于缓冲流。你需要冲洗它
printf("Enter the number of points" );
fflush( stdout);
//...
scanf("%d",&no);
printf("==============================================================\n");
fflush( stdout);
在使用 C++ 流时,您将使用
std::cout.flush(); // or std::cout << flush;
关于c++ - 构造函数中的打印函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23874316/