完整的有关问题,刚才那个发错了,请看看
完整的问题,刚才那个发错了,请各位大哥看看
现在有两个问题,第一个是用cin不能输入空格,用哪个指令能在字符串中输入空格
第二个,输入字符串数组后,在显示的子程序里只能显示出来第一个字符串,怎么修改
#include "stdio.h "
#include <iostream>
#include <cstring>
using namespace std;
unsigned char rulestr[20][100];
int length;
int rule_no;
void add_rule()
{
cout < < "Please type in the rules:\n ";
cin> > rulestr[rule_no];
rule_no=rule_no+1;
}
void remove_rule()
{cout < < "Please select the number to remove\n ";}
void disp_rule()
{
cout < < "Display all the rules!\n ";
int rule_dis=1;
if(rule_dis <=rule_no)
{
cout < <rule_dis < < ": " < <rulestr[rule_dis-1];
rule_dis++;
}
}
void analyze_rule()
{cout < < "Analyzing\n ";}
void main()
{
cout < < "(1). Add a filter rule:\n ";
cout < < "(2). Remove a filter rule:\n ";
cout < < "(3). Display filter rules:\n ";
cout < < "(4). Analyze filter rules:\n ";
cout < < "(5). Exit.\n ";
int comm_no;
do {cin> > comm_no;
if(comm_no==1) add_rule();
if(comm_no==2) remove_rule();
if(comm_no==3) disp_rule();
if(comm_no==4) analyze_rule();
} while (comm_no!=5);
}
------解决方案--------------------
char c[80]={0};
cin.getline(c,79);
cout < <c < <endl;
------解决方案--------------------
问题1,你可以用getch()来获取单个字符来进行判断
问题2,disp_rule()函数中,显示应该用while循环,而不是if,而且你的判断条件有问题。代码如下:
void disp_rule()
{
cout < < "Display all the rules!\n ";
int rule_dis=1;
while(rule_dis <=rule_no+1)
{
cout < <rule_dis < < ": " < <rulestr[rule_dis-1] < <endl;
rule_dis++;
}
}
现在有两个问题,第一个是用cin不能输入空格,用哪个指令能在字符串中输入空格
第二个,输入字符串数组后,在显示的子程序里只能显示出来第一个字符串,怎么修改
#include "stdio.h "
#include <iostream>
#include <cstring>
using namespace std;
unsigned char rulestr[20][100];
int length;
int rule_no;
void add_rule()
{
cout < < "Please type in the rules:\n ";
cin> > rulestr[rule_no];
rule_no=rule_no+1;
}
void remove_rule()
{cout < < "Please select the number to remove\n ";}
void disp_rule()
{
cout < < "Display all the rules!\n ";
int rule_dis=1;
if(rule_dis <=rule_no)
{
cout < <rule_dis < < ": " < <rulestr[rule_dis-1];
rule_dis++;
}
}
void analyze_rule()
{cout < < "Analyzing\n ";}
void main()
{
cout < < "(1). Add a filter rule:\n ";
cout < < "(2). Remove a filter rule:\n ";
cout < < "(3). Display filter rules:\n ";
cout < < "(4). Analyze filter rules:\n ";
cout < < "(5). Exit.\n ";
int comm_no;
do {cin> > comm_no;
if(comm_no==1) add_rule();
if(comm_no==2) remove_rule();
if(comm_no==3) disp_rule();
if(comm_no==4) analyze_rule();
} while (comm_no!=5);
}
------解决方案--------------------
char c[80]={0};
cin.getline(c,79);
cout < <c < <endl;
------解决方案--------------------
问题1,你可以用getch()来获取单个字符来进行判断
问题2,disp_rule()函数中,显示应该用while循环,而不是if,而且你的判断条件有问题。代码如下:
void disp_rule()
{
cout < < "Display all the rules!\n ";
int rule_dis=1;
while(rule_dis <=rule_no+1)
{
cout < <rule_dis < < ": " < <rulestr[rule_dis-1] < <endl;
rule_dis++;
}
}