问题描述
- C++实现命令行功能:`ls`,`cd`,`cat`, `add`, `remove`
-
#题目 要求Browse and modify a JSON data structure with
ls
,cd
,cat
,add
,remove
#实现功能
- Let's say we have this address entry data structure in JSON
{ "entries": { "lilei" : { "age": 27, "mobile" : "13700000000", "address" : "Earth somewhere" }, "hanmeimei" : { "age": 26, "mobile" : "13700000001", "address" : "Earth somewhere else" } } }
- start interactive command line application
sh> ./ab
ab> _
- use
ls
command to list the items in current positionab> ls
ab> entries
- use
cd
command to go to the entry like go to a directoryab> cd entries
ab> ls
ab> lilei hanmeimei
- use
cat
command to display th item dataab> cat lilei
ab> "lilei" : { "age": 27, "mobile" : "13700000000", "address" : "Earth somewhere" }
- use
add
command to add new address entry to JSONab> cd entries
ab> add
key: xiaoming
value: { "age": 28, "mobile" : "13700000002", "address" : "Earth somewhere too" }
address entry added
ab> ls
ab> lilei hanmeimei xiaoming
Note: the key should be identical, if trying to add duplicated key, just display an error message
- use
remove
command to get one or more address entriesab> cd entries
ab> remove
please give the key: xiaoming
xiaoming was deleted from JSON
Note: if trying to delete an non-exist key, just display an error message
- get help
ab> !help
then help message should be displayed, and when encoutering invalid command, help message
should also be displayed. - quit from the application
ab> !quit
sh> _
- Let's say we have this address entry data structure in JSON