⑴ 怎麼用c++模擬內存管理(最壞使用演算法)
csdn 文檔里有 delphi的,樓主可以參考。
⑵ 要求編寫一個動態分區分配管理程序實現一塊模擬內存空間的管理,包括內存分配與回收功能。
1019734138@qq.com 我給你發
⑶ 利用C語言,實現存儲分配演算法,開發一個存儲管理的模擬程序,對內存空間的管理和分配。
參考stl裡面自動管理內存的部分
⑷ 操作系統內存管理模擬實驗
#include<iostream.h>//預處理命令
#define  M  30//定義M值為30
int N;//定義變數N
struct Pro//創建結構體 pro
{
int num,time;//定義變數num和time
};
int Input(int m,Pro p[M])//輸入函數
{   
 cout<<"Please input the actual number of pages:"<<endl ;//利用count在屏幕上輸出並且換行
 do
 {
  cin>>m;//利用cin輸入m的值
  if(m>M)cout<<"Overload,Please enter again"<<endl;//當輸入的m值大於M時候提示出錯
  else break;//否則停止
 }
 while(1);//while循環語句
    cout<<endl<<"Please enter the page number"<<endl;//利用count在屏幕輸文字
    for(int i=0;i<m;i++)//for循環語句,定義i為字元類型初始值為0,當i<m時,i自加
 {
  cin>>p[i].num;//以數字輸入各頁面號
  p[i].time=0;//給p[i].time賦值為0
 }
 return m;//正常結束向操作系統返回一個m值
}void print(Pro *page1)//在屏幕上顯示當前的頁面
{
 Pro *page=new Pro[N];//使用指針進行賦值
 page=page1;//將page1賦值為page
 for(int i=0;i<N;i++)cout<<page[i].num<<"  ";//定義i為字元類型初始值為0,當i<N時,i自加,
//並且在屏幕上輸出頁面號
 cout<<endl;//在屏幕上顯示換行
}
int  Search(int e,Pro *page1  )//查找內存中是否存在要調入的頁面
{
 Pro *page=new Pro[N];//利用指針將page地址賦給pro[N]
 page=page1;//將page的值賦給page1
 for(int i=0;i<N;i++)if(e==page[i].num)return i;//使用for循環語句,定義i為字元類型,
 //當i<N時,i自加,並且當e的值等於頁面號時候返回i
 return -1;//如果正常結束向操作系統返回一個-1值
}
int Max(Pro *page1)//找出離現在時間最長的頁面
{
 Pro *page=new Pro[N];//使用指針將page地址賦給pro[N]
 page=page1;//賦值,將page值賦給page1
 int e=page[0].time,i=0;
 while(i<N)//使用while循環語句判斷當i<N時
 {
  if(e<page[i].time)e=page[i].time;
  i++;//i自加
 }
    for( i=0;i<N;i++)if(e==page[i].time)return i;//for循環語句i初值為0,當i<N的時候
 //i自加,當e的值等於頁面號的時候,正常結束返回一個i值
 return -1;//如果正常結束向操作系統返回一個-1值
}int Compfu(Pro *page1,int i,int t,Pro p[M])//找到最久不使用的頁面
{
 Pro *page=new Pro[N];//使用指針進行賦值
 page=page1;//將page值賦給page1
 
 int count=0;//定義變數count並且賦值為0
 for(int j=i;j<M;j++)//for循環語句定義j為字元類型,賦值為i,當j<M時候,j自加
 {
  if(page[t].num==p[j].num )break;//當二者值相等時候終止
  else count++;//否則count自加
 }
 return count;//返回到conut
 
}
int main()//定義主函數首部
{
    
 cout<<"available Memory page number:"<<endl;//利用count在屏幕上輸出文字
 cin>>N; //輸入N的值
 Pro p[M];
Pro *page=new Pro[N];//利用指針進行賦值
 char c;//定義變數c
 int m=0,t=0;//定義變數m和n並且賦值為0
 float n=0;//定義雙精度變數n並且賦值為0
 m=Input(m,p);//輸入函數 
 do{
  
  for(int i=0;i<N;i++)//初試化頁面基本情況
  {
   page[i].num=0;//將頁面號賦值為0
   page[i].time=2-i;//頁面時間賦值為2-i
  }
        i=0;  
        cout<<"F:FIFO Page replacement"<<endl;//利用count輸出文字並且換行
  cout<<"L:LRU Page replacement"<<endl;//利用count輸出文字並且換行
  cout<<"O:OPT Page replacement"<<endl;//利用count輸出文字並且換行
  cout<<"Press any key end"<<endl;//利用count輸出文字並且換行
  cin>>c;//輸入c的值
  
  if(c=='F')//FIFO頁面置換
  {
   n=1;
   cout<<"the case of Page replacement:   "<<endl;//利用count輸出文字並且換行
   while(i<m)//while循環語句當i<m時候
   {
    if(Search(p[i].num,page)>=0)i++;//找到相同的頁面
    else //否則
    {  
     if(t==N)t=0;//if循環語句判斷t
     else 
     {
      n++;//n自加
      page[t].num=p[i].num;//賦值
      print(page);//在屏幕上顯示page值
      t++;//t自加
     }
  }
   }
   cout<<"number of page lack:"<<n<<"Rate of page lack:"<<n/m<<endl;//利用count在屏幕上
   //輸出並且換行      
   
  }
  if(c=='L')//LRU頁面置換
  {    n=1;
  cout<<"the case of Page replacement:  "<<endl; //利用count在屏幕上輸出並且換行 
  while(i<m)//while循環語句判斷i是否小於m
  {    
   int k;//定義變數k
   k=t=Search(p[i].num,page);
   if(t>=0)//if循環語句判斷t值
    page[t].time=0;//給頁面使用時間賦值
   else//否則
   {  
    n++; //n自加
    t=Max(page);//賦值t
    
    page[t].num=p[i].num;//賦值頁面號
    page[t].time=0;//賦值頁面時間
   }
   if(t==0){page[t+1].time++;page[t+2].time++;}//if循環語句當t等於0時
   if(t==1){page[2].time++;page[0].time++;}//if循環語句當t等於1時
   if(t==2){page[1].time++;page[0].time++;}//if循環語句當t等於2時
            if(k==-1)   print(page);//if循環語句當t等於-1時    
   i++;//i自加
  }
  cout<<"number of page lack:"<<n<<"Rate of page lack:"<<n/m<<endl; //利用count在屏幕上輸出並且換行
  }
  if(c=='O')//OPT頁面置換
  {
   n=1;
   while(i<m)//while循環語句當i<m時候
{
    if(Search(p[i].num,page)>=0)i++;//if循環語句進行查找調入頁面
    else//否則
    {
     int temp=0,cn;//定義自變數temp
     for(t=0;t<N;t++)//for循環語句t<N時候t自加
     {
      if(temp<Compfu(page,i,t,p))//使用if循環語句判斷自變數temp
      {
       temp=Compfu(page,i,t,p);
       cn=t;//賦值
      }
     }
     page[cn]=p[i];//賦值
     n++;//n自加
     print(page);//在屏幕顯示頁面號
     i++;//i自加
    }
   }
   cout<<"number of page lack:"<<n<<"Rate of page lack:"<<n/m<<endl; //利用count在屏幕
   //上輸出並且換行
  }
  
 }while(c=='F'||c=='L'||c=='O');//利用while循環語句返回輸入
 return 0;//當程序正確運行結束,向操作系統返回一個0值
}
⑸ 如何實現模擬內存管理
這個可以運行,你可以自己測試研究下,希望對你有所幫助 #include<iostream.h>//預處理命令
#define  M  40//定義M值為40
int N;//定義變數N
struct Pro//創建結構體 pro
{
int num,time;//定義變數num和time
};
int Input(int m,Pro p[M])//輸入函數
{   
 cout<<"***請輸入實際頁數***:" ;//利用count在屏幕上輸出並且換行
 do
 {
  cin>>m;//利用cin輸入m的值
  if(m>M)cout<<"***數量超出,請重新輸入***"<<endl;//當輸入的m值大於M時候提示出錯
  else break;//否則停止
 }
 while(1);//while循環語句
    cout<<endl<<"***請輸入各頁面號***"<<endl;//利用count在屏幕輸文字
    for(int i=0;i<m;i++)//for循環語句,定義i為字元類型初始值為0,當i<m時,i自加
 {
  cin>>p[i].num;//以數字輸入各頁面號
  p[i].time=0;//給p[i].time賦值為0
 }
 return m;//正常結束向操作系統返回一個m值
}void print(Pro *page1)//在屏幕上顯示當前的頁面
{
 Pro *page=new Pro[N];//使用指針進行賦值
 page=page1;//將page1賦值為page
 for(int i=0;i<N;i++)cout<<page[i].num<<"  ";//定義i為字元類型初始值為0,當i<N時,i自加,
//並且在屏幕上輸出頁面號
 cout<<endl;//在屏幕上顯示換行
}
int  Search(int e,Pro *page1  )//查找內存中是否存在要調入的頁面
{
 Pro *page=new Pro[N];//利用指針將page地址賦給pro[N]
 page=page1;//將page的值賦給page1
 for(int i=0;i<N;i++)if(e==page[i].num)return i;//使用for循環語句,定義i為字元類型,
 //當i<N時,i自加,並且當e的值等於頁面號時候返回i
 return -1;//如果正常結束向操作系統返回一個-1值
}
int Max(Pro *page1)//找出離現在時間最長的頁面
{
 Pro *page=new Pro[N];//使用指針將page地址賦給pro[N]
 page=page1;//賦值,將page值賦給page1
 int e=page[0].time,i=0;
 while(i<N)//使用while循環語句判斷當i<N時
 {
  if(e<page[i].time)e=page[i].time;
  i++;//i自加
 }
    for( i=0;i<N;i++)if(e==page[i].time)return i;//for循環語句i初值為0,當i<N的時候
 //i自加,當e的值等於頁面號的時候,正常結束返回一個i值
 return -1;//如果正常結束向操作系統返回一個-1值
}int Compfu(Pro *page1,int i,int t,Pro p[M])//找到最久不使用的頁面
{
 Pro *page=new Pro[N];//使用指針進行賦值
 page=page1;//將page值賦給page1
 
 int count=0;//定義變數count並且賦值為0
 for(int j=i;j<M;j++)//for循環語句定義j為字元類型,賦值為i,當j<M時候,j自加
 {
  if(page[t].num==p[j].num )break;//當二者值相等時候終止
  else count++;//否則count自加
 }
 return count;//返回到conut
 
}
int main()//定義主函數首部
{
    
 cout<<"***可用內存頁面數***:"<<endl;//利用count在屏幕上輸出文字
 cin>>N; //輸入N的值
 Pro p[M];
Pro *page=new Pro[N];//利用指針進行賦值
 char c;//定義變數c
 int m=0,t=0;//定義變數m和n並且賦值為0
 float n=0;//定義雙精度變數n並且賦值為0
 m=Input(m,p);//輸入函數 
 do{
  
  for(int i=0;i<N;i++)//初試化頁面基本情況
  {
   page[i].num=0;//將頁面號賦值為0
   page[i].time=2-i;//頁面時間賦值為2-i
  }
        i=0;  
        cout<<"***F:FIFO頁面置換***"<<endl;//利用count輸出文字並且換行
  cout<<"***L:LRU頁面置換***"<<endl;//利用count輸出文字並且換行
  cout<<"***O:OPT頁面置換***"<<endl;//利用count輸出文字並且換行
  cout<<"按任意鍵結束"<<endl;//利用count輸出文字並且換行
  cin>>c;//輸入c的值
  
  if(c=='f')//FIFO頁面置換
  {
   n=1;
   cout<<"***頁面置換情況***:   "<<endl;//利用count輸出文字並且換行
   while(i<m)//while循環語句當i<m時候
   {
    if(Search(p[i].num,page)>=0)i++;//找到相同的頁面
    else //否則
    {  
     if(t==N)t=0;//if循環語句判斷t
     else 
     {
      n++;//n自加
      page[t].num=p[i].num;//賦值
      print(page);//在屏幕上顯示page值
      t++;//t自加
     }
  }
   }
   cout<<"***缺頁次數***:"<<n<<"***缺頁率***:"<<n/m<<endl;//利用count在屏幕上
   //輸出並且換行      
   
  }
  if(c=='l')//LRU頁面置換
  {    n=1;
  cout<<"***頁面置換情況***:  "<<endl; //利用count在屏幕上輸出並且換行 
  while(i<m)//while循環語句判斷i是否小於m
  {    
   int k;//定義變數k
   k=t=Search(p[i].num,page);
   if(t>=0)//if循環語句判斷t值
    page[t].time=0;//給頁面使用時間賦值
   else//否則
   {  
    n++; //n自加
    t=Max(page);//賦值t
    
    page[t].num=p[i].num;//賦值頁面號
    page[t].time=0;//賦值頁面時間
   }
   if(t==0){page[t+1].time++;page[t+2].time++;}//if循環語句當t等於0時
   if(t==1){page[2].time++;page[0].time++;}//if循環語句當t等於1時
   if(t==2){page[1].time++;page[0].time++;}//if循環語句當t等於2時
            if(k==-1)   print(page);//if循環語句當t等於-1時    
   i++;//i自加
  }
  cout<<"***缺頁次數***:"<<n<<"***缺頁率***:"<<n/m<<endl; //利用count在屏幕上輸出並且換行
  }
  if(c=='o')//OPT頁面置換
  {
   n=1;
   while(i<m)//while循環語句當i<m時候
{
    if(Search(p[i].num,page)>=0)i++;//if循環語句進行查找調入頁面
    else//否則
    {
     int temp=0,cn;//定義自變數temp
     for(t=0;t<N;t++)//for循環語句t<N時候t自加
     {
      if(temp<Compfu(page,i,t,p))//使用if循環語句判斷自變數temp
      {
       temp=Compfu(page,i,t,p);
       cn=t;//賦值
      }
     }
     page[cn]=p[i];//賦值
     n++;//n自加
     print(page);//在屏幕顯示頁面號
     i++;//i自加
    }
   }
   cout<<"***缺頁次數***:"<<n<<"***缺頁率***:"<<n/m<<endl; //利用count在屏幕
   //上輸出並且換行
  }
  
 }while(c=='f'||c=='l'||c=='o');//利用while循環語句返回輸入
 return 0;//當程序正確運行結束,向操作系統返回一個0值
}
⑹ (4)虛擬內存程序設計,包括FIFO和LRU演算法。 設計一個能模擬內存管理行為的系統程序,該系統至少應包括FI
#include"stdio.h"
#include"stdlib.h"
#include"time.h"
void FIFO(void);
void LRU(void);
char a;
int m=4,n=12,i,y[12]=;  /*m為物理塊數,n為要訪問的頁面數*/
typedef struct page{
 int num;
 int time;
}Page;
Page x[10];
int GetMax(page *x)     /*求出那個物理塊中的頁面呆的時間最長,返回物理塊號*/
{
       int i;
       int max=-1;
       int tag=0;
       for(i=0;i<m;i++)
 {
              if(x[i].time>max)
              {    max=x[i].time;
                     tag=i;
             }
       }
       return tag;
}
void Xunhuan()
{
 printf("Please select  1:FIFO演算法\n               2:LRU演算法\n");
 scanf("%s",&a);
 printf("物理塊數:4\n");
 //scanf("%d",&m);
 for(i=0;i<m;i++)      /*將空的物理塊中數據置為-1*/
 {
  x[i].num=-1;
 }
 printf("所要訪問的頁面數:12\n");
 //scanf("%d",&n);
 //srand(time(NULL));
 printf("所要訪問的頁面號序列為:");
  for(i=0;i<n;i++)
   printf("%d ",y[i]);
  printf("\n");
  printf("頁面置換步驟如下:\n");
 switch(a)
  {
   case '1':FIFO();break;
   case '2':LRU(); break;
  }
}
void main()
{
 char a;
 Xunhuan();
 while(1)
 {
  printf("Continue or Exit:C/Anykey:\n");
  scanf("%s",&a);
  if(a=='c'||a=='C')
  Xunhuan();
  else break;
 }
 exit(0);
}
void FIFO(void)
{
 int i,j,u;
 for(i=0;i<m;i++)
  x[i].time=0;
 x[0].num=y[0];
 x[0].time=1;
 printf(" %d         \n",x[0].num);
 for(i=1;i<n;i++)
 { u=0;
  for(j=0;j<m;j++)
   if(x[j].num==y[i])
   {
    u=1;
    break;
   }
  if(u!=1&&x[m-1].num!=-1)
   {
    j=GetMax(x);
    x[j].num=y[i];
    x[j].time=0;
   }
  if(u!=1&&x[m-1].num==-1)
  {
   for(j=0;j<m;j++)
   {
    if(x[j].num==-1)
    {x[j].num=y[i];
    break;}
   }
  }
   for(j=0;j<m;j++)
   if(x[j].num!=-1)
   x[j].time++;
    
   for(j=0;j<m;j++)
    if(x[j].num==-1)
                     printf("%2c ",32);
    else
                     printf("%2d ",x[j].num);
   printf("\n");
 }
}
void LRU()
{
 int i,j,u;
 for(i=0;i<m;i++)
  x[i].time=0;
 x[0].num=y[0];
 x[0].time=1;
 printf(" %d         \n",x[0].num);
 for(i=1;i<n;i++)
 { u=0;
  for(j=0;j<m;j++)
   if(x[j].num==y[i])    /*物理塊中存在相同頁面*/
   {
    x[j].time=0;      /*將相同的物理塊的time置為0*/
    u=1;
    break;
   }
  if(u!=1&&x[m-1].num!=-1)    /*物理塊中無相同頁面且物理塊已填滿*/
   {
    j=GetMax(x);
    x[j].num=y[i];
    x[j].time=0;        /*將剛替換的頁面所在的物理塊time置為0*/
   }
  if(u!=1&&x[m-1].num==-1)    /*物理塊中無相同頁面且物理塊未填滿*/
  {
   for(j=0;j<m;j++)
   {
    if(x[j].num==-1)
    {x[j].num=y[i];
    break;}
   }
  }
   for(j=0;j<m;j++)
   if(x[j].num!=-1)
     x[j].time++;   /*每執行完一次time加1*/
    
   for(j=0;j<m;j++)
    if(x[j].num==-1)
                     printf("%2c ",32);
    else
                     printf("%2d ",x[j].num);
   printf("\n");         /*格式化輸出*/
 }
}
⑺ 大家好,我想問一個關於模擬內存管理的程序,大家能幫我看看嗎
#include <iostream>
#include <iomanip>
using namespace std;
#define Success  1
#define Failure  0
struct PCB {
 int number;  //進程號
 int need;  //申請資源
};
struct job {
 int ID;//內存塊
 int Address;//內存首地址
 int Len;//
 bool Process;//內存的狀態,有無佔用
 int mark;//
};
template<class T>
struct Node {
 T data;//數據域,存放表元素
 Node *next;//指針域,指向下一個結點
};
template <class T>
class LinkList
{
private:
 Node<T> *Head;// 鏈表頭指針
 void reCount();
public:
 LinkList() ;
 ~LinkList();
 void Insert(int i,T e);
 void my_malloc(int i, int j);
 int  my_free(int handle);
 void my_memlist();
};
template<class T>
LinkList<T>::LinkList()
{//構建函數,建一空鏈表
 Head=new Node<T>;
 Head->next=NULL;
}
template<class T>
LinkList<T>::~LinkList()
{//析構函數,釋放鏈表所佔空間
 Node<T> *p;
 while(Head)//從頭結點開始,依次釋放結點
 {
  p=Head;
  Head=Head->next;
  delete p;
 }
 Head=NULL;//頭結點指向空
}
template<class T>
void LinkList<T>::reCount()
{
 Node<T> *p = Head->next;
 for(int count=1; p; p=p->next, count++)
  (p->data).ID = count;
}
template<class T>
void LinkList<T>::Insert (int i,T e)
{//在指定位置插入元素
 int j=0;
 Node<T> *p;
 p=Head;//工作指針初始化
 while(p && j<i-1)//定位到插入點之前
 {
  p=p->next;//
  j++;
 }
 if(!p||j>i-1) throw"位置異常";//插入位置不合理,i<0或i>表長
 else
 {
  Node<T> *s;
  s=new Node<T>;//
  s->data=e;//
  s->next=p->next;//結點S鏈接到p結點之後
  p->next=s;//
 }
}
template <class T>
void LinkList<T>::my_malloc(int i,int j)
{
 Node<T> *p = NULL;
 Node<T> *r = Head->next;
 Node<T> *q = new Node<T>;
 int minMem = 101;
 while(r) {
  if((r->data).Len >= j && !(r->data).Process && (r->data).Len < minMem) {
   p = r;
   minMem = (r->data).Len;
  }
  r = r->next;
 }
 if(p==NULL){cout<<"NULL"<<endl;return;}
 (q->data).ID  = 0;
 (q->data).Len  = (p->data).Len - j;
 (q->data).Address = (p->data).Address + j;
 (q->data).Process = false;
 (p->data).Len  = j;
 (p->data).Process = true;
 (p->data).mark  = i;
 q->next = p->next;
 p->next = q;
 if((q->data).Len == 0) {p->next = q->next; delete q;}
 reCount();
 cout<<(p->data).Address<<endl;
}
template<class T>
int LinkList<T>::my_free(int handle)
{
 Node<T> *p = Head;
 Node<T> *q = Head->next;
 while((q->data).Address != handle) {
  p=p->next;
  q=q->next;
  if(q==NULL)
   return Failure;
 }
 (q->data).Process = false;
 Node<T> *r = q->next;
 if(r!=NULL&&!(r->data).Process) {
  (q->data).Len += (r->data).Len;
  q->next = r->next;
  delete r;
 }
 if(p==Head){
  reCount();
  return Success;
 }
 if(!(p->data).Process) {
  (p->data).Len += (q->data).Len;
  p->next = q->next;
  delete q;
 }
 reCount();
 return Success;
}
template <class T>
void LinkList<T>::my_memlist()
{
 Node<T> *p;
 p=Head->next;
 while(p!=NULL)
 {
  cout<<(p->data).ID<<setw(10)<<(p->data).Address<<setw(10)<<(p->data).Len<<setw(10);
  if ((p->data).Process)
  {
   cout<<(p->data).mark;
  }
  else  cout<<"NULL";
  cout<<endl;
  p=p->next;
 }
}
void Display()
{
 cout<<"1--分配內存:"<<endl;
 cout<<"2--回收內存:"<<endl;
 cout<<"3--查看內存:"<<endl;
 cout<<"4------退出:"<<endl;
 cout<<"請輸入選擇 :";
}
int main(void)
{
 LinkList<job> memory;
 job Empty;
 Empty.Address = 0;
 Empty.ID      = 0;
 Empty.Len     = 100;
 Empty.Process = false;
 memory.Insert(1,Empty);
 int handle;
 PCB thread;
Display();
 int choice;
 cout.setf(ios::right);
 do {
  cin>>choice;
  switch (choice) {
  case 1:
   cout<<"請輸入進程號:";
   cin>>thread.number;
   cout<<"請輸入工作需要內存數:";
   cin>>thread.need;
   memory.my_malloc(thread.number, thread.need);
   break; 
  case 2:
   cout<<"請輸入需要回收的首地址:";
   cin>>handle;
   memory.my_free(handle);
   break;
  case 3:
   cout<<"ID"<<setw(10)<<"Address"<<setw(10)<<"Len"<<setw(10)<<"Process"<<endl;
   memory.my_memlist();
   break;
  }
  cin.clear();
  fflush(stdin);
 } while (choice != 4);
 return 0;
}
⑻ 急求模擬內存管理源代碼
右擊我的電腦。屬性,高級,性能設置,高級,下面有個虛擬內存,改大點就好了。
⑼ 模擬內存管理程序,求大神幫看看錯在哪
#include<stdio.h>
int main(void)
{
	   double T = 0.00;
	   double K = 0.00;
	   int A = 0;
	   printf("If you want to temperatures from Celsius to Fahrenheit,please enter 1\n");
	   printf("If you want to temperatures from Fahrenheit to Celsius,please enter 2\n");
	   scanf(" %d",&A);
	
	   switch ( A )
	   {
		       case 1:
			           printf("Please enter a Celsius temperature scale :");
			           scanf("%lf",&T);
			           K = 1.8*T+32;
			           printf("You entered a Centigrade temperature scale %lf ,and can be converted to Fahrenheit scale %lf  ", T,K);
			           break;
	
		   case 2:
			       printf("Please enter a Fahrenheit temperature scale :");
			       scanf("%lf",&K);
			       T = (K - 32)* 5/9;
			       printf("You entered a Fahrenheit temperature scale %lf ,and can be converted to Celsius temperature scale %lf ", K ,T);
			       break;
		   default:
			       printf("Please select the correct temperature conversion");
			       break;
	   }
	   printf("按任意鍵結束!");
	   getchar();
	   getchar();
	   return 0;
}
我加了兩個
   getchar();
   getchar();
第一個是接收你輸入1或2後的回車,第二個是等待你的任意鍵,然後到return 0;結束整個程序。
求給力!