[分享]界面比较友善的控制台C++程序初始模版
本帖最后由 u011873969 于 2013-12-04 02:49:48 编辑 主要的就是避免了某些IDE在程序运行结束时自动跳出的现象,并且有纠错机制,可以让你避免因为误按键而造成跳出(默认的是按ESC键退出,并且退出前要你确认。如果否定的话,还可以继续留恋)。
//
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <fstream>
#include <conio.h>
// A brief description to the current program.
inline void introduction()
{
std::cout<<"This program, is stored in the location\n\n"<<__FILE__
<<"\n\nAnd it is compiled on \t"<<__DATE__"\t at "
<<__TIME__<<"\nEnjoy this program!\n\n";
}
void escape_program();
int main()
{
// using namespace std;--->这个视情况而用
introduction();
escape_program();
}
// the _getch() function uses conio.h
void escape_program()
{
std::cin.ignore();
std::cout<<"\nPress ESC to exit:";
char ch;
do
{
ch=_getch();
}while(ch != 27);
std::cout<<"Would you like to exit the program? Y or N:\n";
std::cin>>ch;
char symbol;
do
{
std::cin.get(symbol);
}while(symbol != '\n');
if(ch == 'Y' || ch == 'y')
return;
else
escape_program();
}