首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

[分享]界面比较友好的控制台C++程序初始模版

2013-12-10 
[分享]界面比较友善的控制台C++程序初始模版本帖最后由 u011873969 于 2013-12-04 02:49:48 编辑主要的就

[分享]界面比较友善的控制台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();
}

[解决办法]
楼主这么做,置system(“pause”); 与何地?
[解决办法]
main放中间差评。无视argv差评。27差评。

[解决办法]
姑且认为你这个是模板,别人拿到如何使用。

热点排行