C/C++ 控制台程序执行一闪而过

问题:

在 VS2017(或其他IDE) 编写控制台程序的时候,经常会看到程序的执行结果一闪而过,要解决这个问题,有一些简单方法。

解决:

1.在结尾使用 system(“pause”);
2.在 C 中,使用 getchar();

int main()
{
	printf( "hello,word\n");
	getchar();

	return 0;	
}

3.在 C++ 中,使用 cin.get();

int main()
{
	cout << "hello,word\n";
	cin.get();

	return 0;	
}

4.使用keep_window_open();

int main()
{
	cout << "hello,word\n";
//	cin.get();
	keep_window_open();
	return 0;	
}

或者使用其他可接受键盘输入的函数也没问题。

你可能感兴趣的:(C/C++)