KeyValues* pRootKey = new KeyValues("root"); // add two subkeys to the root key pRootKey->AddSubKey(new KeyValues("subkey1")); pRootKey->AddSubKey(new KeyValues("subkey2")); // retrieve the first subkey using GetFirstSubKey KeyValues* pSubKey = pRootKey->GetFirstSubKey(); // output the name of the first subkey ("subkey1") std::cout << pSubKey->GetName() << std::endl;
KeyValues* pRootKey = new KeyValues("root"); // add three subkeys to the root key pRootKey->AddSubKey(new KeyValues("subkey1")); pRootKey->AddSubKey(new KeyValues("subkey2")); pRootKey->AddSubKey(new KeyValues("subkey3")); // retrieve the first subkey using GetFirstSubKey KeyValues* pSubKey = pRootKey->GetFirstSubKey(); // loop through all subkeys using GetNextKey while (pSubKey) { // output the name of each subkey ("subkey1", "subkey2", "subkey3") std::cout << pSubKey->GetName() << std::endl; // get the next subkey pSubKey = pSubKey->GetNextKey(); }In this example, we create a KeyValues object called `pRootKey` and add three subkeys to it. We then use the `GetFirstSubKey` function to retrieve the first subkey and loop through all of the subkeys using `GetNextKey`. We output the name of each subkey. Package/library: KeyValues library in C++.