![Contributors](https://camo.githubusercontent.com/833468118371d8a008f43b774d76bc93ff4fe103bff8c304613f8e42cb2a8fcd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f42656172646564466973682f696e692d7277)
![ini-rw: A .ini file reader and writer library programmed in C++17. ini-rw: A .ini file reader and writer library programmed in C++17.](/BeardedFish/ini-rw/raw/master/images/ini-rw-banner.png)
- Ability to open
.ini
files for either:
- Ability to save changes to a
.ini
file if modified
- Inline comment support for
.ini
sections and keys
#include "IniFile.hpp"
#include <iostream>
#include <string>
int main()
{
inirw::IniFile iniFile("path_to_ini_file");
if (iniFile) // You could also use iniFile.is_loaded() instead
{
inirw::IniKey* iniKey = iniFile.get_key("section_name", "key_name");
if (iniKey)
{
std::cout << "INI key information:\n";
std::cout << "====================\n";
std::cout << "Section: " << iniKey->get_section()->get_name() << '\n';
std::cout << "Value: " << iniKey->ValueCommentPair.get_value() << '\n';
std::cout << "Comment: " << iniKey->ValueCommentPair.get_comment() << '\n' << '\n';
}
else
{
std::cout << "The INI key was not found.\n";
}
iniFile.write_key_value<std::string>("library", "name", "ini-rw");
iniFile.write_key_value<int>("library", "cpp_standard", 17);
iniFile.write_key_value<bool>("library", "is_open_source", true);
// Insert a pound symbol comment at the top of the loaded INI file
iniFile.insert_comment(inirw::IniCommentPrefix::Pound, "Hello, World!");
if (iniFile.save_changes())
{
std::cout << "The INI file was saved successfully!\n";
}
}
else
{
std::cout << "Unable to open the INI file.\n";
}
}