| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 592 人关注过本帖
标题:请教!我的程序为什么编译时出现错误?
只看楼主 加入收藏
lbxj
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-1-4
收藏
 问题点数:0 回复次数:3 
请教!我的程序为什么编译时出现错误?

我使用TURBO C++ 2.0或3.0调试一个操作系统上机例题,编译时总在#include<iostream.h>句上提示error Must use C++ for the type iostream.错误,不知为何,请于赐教,不胜感谢.急急急!!!

原程序如下:
#include<stdio.h>
#include <dos.h>
#include<stdlib.h>
#include<conio.h>
#include<iostream.h>
#define P_NUM 5
#define P_TIME 50
enum state{
ready,
execute,
block,
finish
};

struct pcb{
char name[4];
int priority;
int cputime;
int needtime;
int count;
int round;
state process;
pcb * next;
};
pcb * get_process();
pcb * get_process(){
pcb *q;
pcb *t;
pcb *p;
int i=0;
cout<<"input name and time"<<endl;

while (i<P_NUM){
q=(struct pcb *)malloc(sizeof(pcb));
cin>>q->name;
cin>>q->needtime;
q->cputime=0;
q->priority=P_TIME-q->needtime;
q->process=ready;
q->next=NULL;
if (i==0){
p=q;
t=q;
}
else{
t->next=q;
t=q;
}
i++;
} //while
return p;
}
void display(pcb *p){
cout<<"name"<<" "<<"cputime"<<" "<<"needtime"<<" "<<"priority"<<" "<<"state"<<endl;
while(p){
cout<<p->name;
cout<<" ";
cout<<p->cputime;
cout<<" ";
cout<<p->needtime;
cout<<" ";
cout<<p->priority;
cout<<" ";
switch(p->process){
case ready:cout<<"ready"<<endl;break;
case execute:cout<<"execute"<<endl;break;
case block:cout<<"block"<<endl;break;
case finish:cout<<"finish"<<endl;break;
}
p=p->next;
}
}

int process_finish(pcb *q){
int bl=1;
while(bl&&q){
bl=bl&&q->needtime==0;
q=q->next;
}
return bl;
}

void cpuexe(pcb *q){
pcb *t=q;
int tp=0;
while(q){
if (q->process!=finish){
q->process=ready;
if(q->needtime==0){
q->process=finish;
}
}
if(tp<q->priority&&q->process!=finish){
tp=q->priority;
t=q;
}
q=q->next;
}
if(t->needtime!=0){
t->priority-=3;
t->needtime--;
t->process=execute;
t->cputime++;
}
}

void priority_cal(){
pcb * p;
clrscr();
p=get_process();
int cpu=0;
clrscr();
while(!process_finish(p)){
cpu++;
cout<<"cputime:"<<cpu<<endl;
cpuexe(p);
display(p);
sleep(2);
clrscr();
}
printf("All processes have finished,press any key to exit");
getch();
}

void display_menu(){
cout<<"CHOOSE THE ALGORITHM:"<<endl;
cout<<"1 PRIORITY"<<endl;
cout<<"2 ROUNDROBIN"<<endl;
cout<<"3 EXIT"<<endl;
}
pcb * get_process_round(){
pcb *q;
pcb *t;
pcb *p;
int i=0;
cout<<"input name and time"<<endl;

while (i<P_NUM){
q=(struct pcb *)malloc(sizeof(pcb));
cin>>q->name;
cin>>q->needtime;
q->cputime=0;
q->round=0;
q->count=0;
q->process=ready;
q->next=NULL;
if (i==0){
p=q;
t=q;
}
else{
t->next=q;
t=q;
}
i++;
} //while
return p;
}

void cpu_round(pcb *q){
q->cputime+=2;
q->needtime-=2;
if(q->needtime<0) {
q->needtime=0;
}
q->count++;
q->round++;
q->process=execute;

}

pcb * get_next(pcb * k,pcb * head){
pcb * t;
t=k;
do{
t=t->next;
}
while (t && t->process==finish);


if(t==NULL){
t=head;

while (t->next!=k && t->process==finish){
t=t->next;
}
}
return t;
}
void set_state(pcb *p){
while(p){
if (p->needtime==0){
p->process=finish;

}
if (p->process==execute){
p->process=ready;
}
p=p->next;
}
}
void display_round(pcb *p){
cout<<"NAME"<<" "<<"CPUTIME"<<" "<<"NEEDTIME"<<" "<<"COUNT"<<" "<<"ROUND"<<" "<<"STATE"<<endl;
while(p){
cout<<p->name;
cout<<" ";
cout<<p->cputime;
cout<<" ";
cout<<p->needtime;
cout<<" ";
cout<<p->count;
cout<<" ";
cout<<p->round;
cout<<" ";
switch(p->process){
case ready:cout<<"ready"<<endl;break;
case execute:cout<<"execute"<<endl;break;
case finish:cout<<"finish"<<endl;break;
}
p=p->next;
}
}

void round_cal(){
pcb * p;
pcb * r;
clrscr();
p=get_process_round();
int cpu=0;
clrscr();
r=p;
while(!process_finish(p)){
cpu+=2;
cpu_round(r);
r=get_next(r,p);
cout<<"cpu "<<cpu<<endl;
display_round(p);
set_state(p);
sleep(5);
clrscr();
}
}

void main(){
display_menu();
int k;
scanf("%d",&k);
switch(k){
case 1:priority_cal();break;
case 2:round_cal();break;
case 3:break;
display_menu();
scanf("%d",&k);
}
}

搜索更多相关主题的帖子: 编译 
2006-01-04 23:14
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 
写成include<iostream>试试看?

成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-01-05 09:54
激情依旧
Rank: 1
等 级:新手上路
威 望:2
帖 子:524
专家分:0
注 册:2005-4-4
收藏
得分:0 
    没办法帮你.我从来都不用TURBO C++ 2.0或3.0 .用.net来写c++的程序爽.

生是编程人!!!!死是编程鬼!!!!颠峰人生!!!焚尽编程!!! 爱已严重死机!情必须重新启动!情人已和服务器断开连接!网恋也需要重新拨号!-----激情依旧
2006-01-05 10:05
踏魔狼
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:1322
专家分:33
注 册:2005-9-22
收藏
得分:0 
我从不用.net写控制台程序的,那感觉就象是拿着大刀吃西餐!

=×&D o I p R e E n C g T l X&×=
2006-01-05 10:55
快速回复:请教!我的程序为什么编译时出现错误?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016878 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved