控制台菜单
来源:互联网 发布:硅基生命 知乎 编辑:程序博客网 时间:2024/05/21 04:21
菜单是程序中获得用户输入的有效手段。
在控制台环境中菜单也能发挥重要作用。
本程序的目的是要实现一个动态菜单,即:菜单的级次、内容不是固定的,而是定义在a.txt文件中。
程序读入该文件,在内存中动态构建菜单项间的关系,然后运行该菜单。
在控制台环境中菜单也能发挥重要作用。
本程序的目的是要实现一个动态菜单,即:菜单的级次、内容不是固定的,而是定义在a.txt文件中。
程序读入该文件,在内存中动态构建菜单项间的关系,然后运行该菜单。
注意:a.txt中的空白是Tab(制表符),不是空格。
控制台输入
#include<iostream>#include<fstream>#include<string>using namespace std;struct Jgt{ char ch[20]; struct Jgt *brother,*child,*father;};int f(char ch[])//得到每行的制表符个数{ int i=0; while(ch[i]=='\t')i++; return i;}void h(char ch1[],char ch2[],int m)//辅助字符串{ int i=m; while(ch2[i]!='\0') { ch1[i-m]=ch2[i]; i++; } ch1[i-m]='\0';}/*void g(struct Jgt *p)//便利每个节点{ if(p->father)cout<<p->father->ch<<"\t"; cout<<p->ch<<endl; if(p->child)g(p->child); if(p->brother)g(p->brother);}*/int main(){ ifstream file("a.txt"); struct Jgt *jgt=new struct Jgt(); char ch[100]; file.getline(ch,100); strcpy(jgt->ch,ch); jgt->child=jgt->brother=jgt->father=NULL; struct Jgt *p=jgt; int i=0; while(file.getline(ch,100)) { struct Jgt *q=new struct Jgt(); q->child=q->brother=q->father=NULL; int j=f(ch); h(q->ch,ch,j); if(j==i+1) { p->child=q; q->father=p; } else { while(i>j) { p=p->father; i--; } p->brother=q; q->father=p->father; } i=j; p=q; } p=jgt; //g(p); while(p) { i=1; struct Jgt *q=p; cout<<"-----------"<<endl; while(p) { cout<<i++<<"."<<p->ch<<endl; p=p->brother; } cout<<i<<".上一层"<<endl; cout<<"-----------"<<endl; cout<<"请输入:"; int n; cin>>n; if(n==i)p=q->father; else { while(n-->1)q=q->brother; p=q->child; } } system("pause"); return 0;}
0 0
- 控制台菜单
- 控制台菜单
- c++ 控制台菜单 制作
- C++ 控制台菜单
- 添加DOS命令(CMD控制台)到文件夹右键菜单
- VC++无效化控制台窗口的关闭按钮(菜单)
- 控制台
- 控制台
- 控制台
- 控制台
- 控制台
- 利用Windows XP的恢复控制台修复受损的双启动菜单
- C语言实现一个Window控制台带彩色,且可以用方向键选择并确认的菜单式列表(一)
- 菜单
- 菜单
- 菜单
- 菜单
- 菜单
- 黑马程序员_交通灯管理系统笔记
- UIView的clipsTobounds属性
- iPhone中的UIApplication详解
- POJ 3974 Palindrome 最长回文子串(manacher算法)
- Ubuntu下gcc安装及使用
- 控制台菜单
- 【面试珠玑】再谈C++的多态
- 【poj2588】Snakes
- 如何添加jar包,以及如何查看jar包源代码
- Python——类属性/实例属性
- 算法概论思维导图
- TopCoder SRM 612 DIV 1 450 SpecialCells
- hosts
- HDU1054Strategic Game【二分图最大独立集】