C语言执行时,程序控制台输出窗口 一闪而过的问题!

有时候,我们在写C时,执行会遇到控制台窗口一闪而过的情况。

首先,我们来看一段代码:

#include<stdio.h>

void main()
{
	printf("--------------hello world!---------");
}

这段代码运行就会出现上述情况。如何解决呢?

解决办法:

法一、getchar();

在主函数的最后加上getchar()

#include<stdio.h>

void main()
{
	printf("--------------hello world!---------");
	getchar();
}

法二、 system("pause");

在主函数尾部插入system("pause");

#include<stdio.h>

void main()
{
	printf("--------------hello world!---------");
	system("pause");
}



猜你喜欢

转载自blog.csdn.net/qq_41953685/article/details/80715771