本文整理汇总了C++中PTree::del方法的典型用法代码示例。如果您正苦于以下问题:C++ PTree::del方法的具体用法?C++ PTree::del怎么用?C++ PTree::del使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PTree
的用法示例。
在下文中一共展示了PTree::del方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
PTree<string> pt;
// normal get
string name("Alice");
pt.put("person.name", name);
string nameOut = pt.get("person.name"); // assignment syntax
assert(name == nameOut);
string nameEx(pt.get<string>("person.name")); // explicit syntax, need convert explicitly
assert(name == nameEx);
assert(pt.isValidPath("person.name"));
// const get
const PTree<string>& cpt = pt;
string nameOutC = cpt.get("person.name");
assert(name == nameOutC);
string nameExC;
nameExC = cpt.get<string>("person.name");
assert(name == nameExC);
const string& nameRefC = cpt.get("person.name");
assert(name == nameRefC);
// ref get
string& nameRef = pt.get("person.name");
nameRef = "Bob";
nameOut = pt.get<string>("person.name");
assert(nameRef == nameOut);
// other types
int age = 25;
pt.put("person.age", age);
int ageOut(pt.get("person.age"));
assert(age == ageOut);
float height = 1.65;
pt.put("person.height", height);
float heightOut(pt.get("person.height"));
assert(height == heightOut);
Car car;
car.color = "black";
car.price = 50000;
pt.put("person.car", car);
Car carOut(pt.get("person.car"));
assert(car.color == carOut.color);
assert(car.price == carOut.price);
// push as vector
int income = 100;
pt.push("person.deposit", income++);
pt.push("person.deposit", income++);
pt.push("person.deposit", income++);
const std::vector<int>& sum = pt.get("person.deposit");
assert(sum.size() == 3);
// del
string error;
pt.del("person.name");
try {
pt.get("person.name");
} catch (const PTreeError& e) {
error = e.what();
cout << "catched PTreeError: " << error << endl;
}
assert(!error.empty());
assert(!pt.isValidPath("person.name"));
cout << "all test passed" << endl;
return 0;
}