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

我是个初学者,编了个小程序,可是一个简单的输出语句,他却跳出一个找ostream的对话框 很不懂啊,请高手帮忙! #include<iostream.h> #include<stdio.h> #include<string.h> #include<process.h> class book {friend class list; private :char name[20]; char tele[11]; int n; book*next; }; class list {private:book*head,*tail,*now; public: list(); void init(void); void print1(void); void add(void); void search(void); void del(void); // void modify(void); void exit(void); }; int main(void)

{char ch; cout<<"Hello!"; list list1; list1.init(); L1:cout<<"press 1 to print the telephone book"; cout<<"press 2 to add record to the telephone book"; cout<<"press 3 to delete a record in the telephone book"; cout<<"press 4 to modify the telephone book"; cout<<"press 5 to search a record in the telephone book"; cout<<"press 6 to exit the program"; cin>>ch;

搜索更多相关主题的帖子: 输出 
2005-10-03 12:36
renjkl
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-10-3
收藏
得分:0 

这时我的程序,请高手指点 #include<iostream.h> #include<stdio.h> #include<string.h> #include<process.h> class book {friend class list; private :char name[20]; char tele[11]; int n; book*next; }; class list {private:book*head,*tail,*now; public: list(); void init(void); void print1(void); void add(void); void search(void); void del(void); // void modify(void); void exit(void); }; int main(void)

{char ch; cout<<"Hello!"; list list1; list1.init(); L1:cout<<"press 1 to print the telephone book"; cout<<"press 2 to add record to the telephone book"; cout<<"press 3 to delete a record in the telephone book"; cout<<"press 4 to modify the telephone book"; cout<<"press 5 to search a record in the telephone book"; cout<<"press 6 to exit the program"; cin>>ch; while(1) { switch(ch) {case'1':list1.print1();break; case'2':list1.add();break; case'3':list1.del();break; //case'4':list1.modify();break; case'5':list1.search();break; case'6':list1.exit();break; default: {cout<<"please input a right number"; goto L1; } break; } cin>>ch; }

return 0; } list::list(void) {head=tail=now=0;} void list::print1(void) {int i; now=head; cout<<"name telephone n "<<endl; for(i=0;i<tail->n;i++) {cout<<now->name<<" "<<now->tele<<" "<<now->n<<endl; now=now->next; } } void list::add(void) {now=new book; cout<<"name:"; cin>>now->name; cout<<endl<<"telephone:"; cin>>now->tele; now->n=tail->n+1; tail->next=now; tail=now; } void list::del(void) {book*a; char na[20]; int i,k=0; char m; cout<<"Input the name you want to delete:"; cin>>na; now=a=head; for(i=0;i<tail->n;i++) if(!strcmp(a->name,na)) { cout<<"name telephone n "<<endl; cout<<a->name<<" "<<a->tele<<" "<<a->n<<endl; k++; cout<<"Do you want to delete it?(Y/N)"; cin>>m; if(m=='y'||m=='Y') {now->next=a->next; delete a; a=now->next; } } else {now=a; a=a->next; } if(k==0) cout<<"there is no such person";

} void list::search(void) {int i,k=0; char na[20]; cout<<"Input the name you want to find:"; cin>>na; now=head; for(i=0;i<tail->n;i++) if(!strcmp(now->name,na)) { cout<<"This is the record you want to find:"<<endl; cout<<"name telephone n "<<endl; cout<<now->name<<" "<<now->tele<<" "<<now->n<<endl; k++; } else now=now->next; if(k==0) cout<<"there is no such person";

} void list::exit(void) {int i; FILE*fp; if((fp=fopen("telebook.dat","w"))==NULL) cout<<"wrong"; else cout<<"success"; now=head; for(i=0;i<tail->n;i++) {fwrite(now,sizeof(book),1,fp); now=now->next; } fclose(fp); now=head; for(i=0;i<tail->n;i++) {head=head->next; delete now; now=head; } exit(); } void list::init(void) { FILE*fp; book buffer; cout<<"name:"; cin>>buffer.name; cout<<endl<<"telephone:"; cin>>buffer.tele; buffer.n=1; if((fp=fopen("telebook.dat","w"))==NULL) cout<<"wrong"; else cout<<"success"; fwrite(&buffer,sizeof(book),1,fp); fclose(fp); if((fp=fopen("telebook.dat","r"))==NULL) cout<<"wrong"; else cout<<"success"; while(!feof(fp)) {fread(&buffer,sizeof(book),1,fp); if(buffer.n==1) {head=now=tail=new book; strcpy(tail->name,buffer.name); strcpy(tail->tele,buffer.tele); tail->n=buffer.n; } else {tail=new book; now->next=tail; strcpy(tail->name,buffer.name); strcpy(tail->tele,buffer.tele); tail->n=buffer.n; } fclose(fp); } }

2005-10-03 12:38
快速回复:为什么连基本的输出都不行?
数据加载中...
 
   



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

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