Skip to content

Instantly share code, notes, and snippets.

@FurryHead
Created June 27, 2011 16:23
Show Gist options
  • Save FurryHead/1049211 to your computer and use it in GitHub Desktop.
Save FurryHead/1049211 to your computer and use it in GitHub Desktop.
ConfigParser test file
/*
* main.cxx
*
* Copyright 2011 FurryHead <[email protected]>
*
* ConfigParser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ConfigParser is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ConfigParser; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <iostream>
#include <string>
#include <vector>
#include "configparser.hxx"
using namespace std;
int main() {
try {
ConfigParser cp("conf.ini");
vector<string> sections = cp.sections();
for (vector<string>::iterator j = sections.begin(); j != sections.end(); ++j) {
cout << "======= Section " << *j << " =======" << endl;
vector<string> options = cp.options(*j);
for (vector<string>::iterator i = options.begin(); i != options.end(); ++i)
cout << "'" << *i << "' = '" << cp.get(*j,*i) << "'" << endl;;
cout << endl;
}
vector<string> options = cp.options("DEFAULT");
if (options.size() > 0) {
cout << "======= Section DEFAULT =======" << endl;
for (vector<string>::iterator i = options.begin(); i != options.end(); ++i)
cout << "'" << *i << "' = '" << cp.get("DEFAULT",*i) << "'" << endl;;
}
} catch(SyntaxError se) {
cout << "SyntaxError: " << se.what() << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment