Update README.md

master
呓喵酱 5 years ago committed by GitHub
parent 00936ce879
commit 3a5cee4188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 66
      docs/ovo_index/README.md

@ -1,4 +1,4 @@
## Class ovo::data
## Class ovo::index
### 快速开始
- 使用以下代码快速开始
@ -8,65 +8,21 @@
int main()
{
ovo::data d;
ovo::index i;
d["name"] = "Tomato"; //插入数据
std::cout << d["name"] << endl; //输出数据
i.push_back("22", "qwertyujk"); //插入一组数据,第一个为值,第二个为索引
i.push_back("22", "23456789");
i.push_back("33", "32wfr2wef23");
return 0;
}
````
以上代码将输出:
> Tomato<br/>
### 进阶使用
- 使用以下代码进阶
````C++
#include <iostream>
#include "ovo.h"
int main()
{
ovo::data d;
d["name"] = "Potato"; //插入数据,前面是键名,后面是键值
d["kk"] = 97; //这种写法无法插入数字,这里实际上插入的是ASCII码'a'
//插入数字请使用insert()
d.insert("num", 97); //这样将插入数字
d.insert("float", 3.1415926); //插入浮点数,最高支持15位有效数字
std::cout << d["name"] << endl; //输出数据无论你的输入格式如何数据的输出格式将是string
//如果你想使用其它类型请由string类型转换
d.size(); //返回data的大小,即包含几个键值对,包括undefined内容
d.isExist("name"); //查看某键名是否存在,存在返回true,否则为false
d.classify(); //整理data,清除包含undefined内容
//d.clear(); //清空所有data
d.clear("name"); //删除"name"键值对
//如果你想遍历元素,请使用内置迭代器,方法如下
d.iter = d.begin();
for(;d.iter != d.end(); d.iter++){
std::cout << "Key: " << d.iter->first << " val: " << d.iter->second << std::endl;
}
vector<string> v = i.getIndex("22"); //根据值提前索引
string s = i.getVal("32wfr2wef23"); //根据索引提值
//另一种遍历方法
d.forEach([&](string first, string second){
std::cout << "Key: " << first << " val:" << second << std::endl;
});
i.delByVal("33"); //根据值删除数据
i.delByIndex("32wfr2wef23"); //根据索引删除数据
//JSON格式显示全部元素,返回一个字符串
std::cout << d.showAll() << std::endl;
std::string s = d.dataToStr(d); //Data转换为string
ovo::data d2 = d2.strToData(s); //string转换为Data
d.attachData("DataItem", d2); //向d追加一条键名为"DataItem", 内容为d2的item
i.size(); //获取大小
return 0;
}
````
以上代码将输出
> Potato<br/>
> Key: float val: 3.1415926<br/>
> Key: kk val: a<br/>
> Key: num val: 97<br/>

Loading…
Cancel
Save