Skip to content

scl::config_file::iterator Documentation

WizardCarter edited this page Jul 6, 2018 · 1 revision

scl::config_file::iterator

This page provides documentation for config_file::iterator, the iterator implementation for config_file. config_file::iterator meets most semantic requirements for a Random Access Iterator. However, it only provides read-access to the data in a config_file. Write-access is a planned feature for a future version of SCL. Additionally, the pointer member access operator (->) does not yet function properly. It is also important to note that the value part of the pair returned when dereferencing a config_file::iterator is always a string, so conversion of second value of the pair to its appropriate type is left up to the user.

Examples

Looping through all key-value pairs in a file.

using namespace scl;
config_file file("example.config", config_file::READ);
file.load();

//loop through all pairs of the file
for (config_file::iterator it = file.begin() ; it != file.end() ; it++) {
    cout << (*it).first << " " << (*it).second << '\n';
}

//same thing as above, but with an enhanced for loop
for (auto p : file) {
    cout << p.first << " " << p.second << '\n';
}

Output last value pair in the file

pair<string, string> p = *(file.end() - 1);
cout << p.first << " " << p.second << '\n';

Clone this wiki locally