-
Notifications
You must be signed in to change notification settings - Fork 5
/
help.h
76 lines (71 loc) · 1.44 KB
/
help.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef HELP_H
#define HELP_H
#include<string>
#include<map>
#include<iostream>
class help
{
public:
map<string,string> keywords;
help();
void show();
string show(string key);
};
help::help(){
fstream file;
file.open("keyword.txt");
if(file.fail()){
cout<<"cannot read keywords configuration file";
}
string s="";
while(file){
string p;
getline(file,p);
s+=p;
}
string k="",v="";
int flag=0;
for(unsigned int i=0;i< s.length();i++){
if(flag==0){
if(s[i]==':'){
flag=1;
continue;
}
k+=s[i];
}
else{
if(s[i]==';'){
keywords.insert({k,v});
k="";v="";
flag=0;
continue;
}
v+=s[i];
}
}
}
void help::show(){
map<string,string>::iterator it;
for(it=keywords.begin();it!=keywords.end();it++){
cout<<"- "<<it->first<<"\n";
}
}
string help::show(string key){
map<string,string>::iterator it;
int p=0;
for(it=keywords.begin();it!=keywords.end();it++){
if(it->first==key){
p=1;
break;
}
}
if(p==1){
if(keywords.at(key)!="\0")
return keywords.at(key);
else
return "doesn't exist";
}
else
return "doesn't exist";
}
#endif // HELP_H