libnbt++3 is a remake of the old libnbt++2 library with the goal of making it more easily usable and fixing some problems. The old libnbt++2 especially suffered from a very convoluted syntax and boilerplate code needed to work with NBT data.
This project uses CMake for building. Ensure you have CMake installed.
Clone the repository:
git clone https://github.com/Project-Tick/Project-Tick.git
cd Project-Tick/libnbtplusplus/
Create a build directory:
mkdir build
cd build
Configure with CMake:
cmake ..
Options:
NBT_BUILD_SHARED=OFF (default): Build static libraryNBT_USE_ZLIB=ON (default): Enable zlib supportNBT_BUILD_TESTS=ON (default): Build testsBuild:
cmake --build .
Install (optional):
cmake --install .
Include the headers and link against the library.
#include <nbt_tags.h>
#include <fstream>
#include <iostream>
int main() {
// Read an NBT file
std::ifstream file("example.nbt", std::ios::binary);
nbt::tag_compound root = nbt::io::read_compound(file).first;
// Access data
std::cout << root["some_key"].as<nbt::tag_string>() << std::endl;
return 0;
}