1. 获取cpptoml
只需要 cpptoml.h 。
$ git clone https://github.com/skystrife/cpptoml.git
2. TOM配置
mysql.toml配置文件如下:
[Title]
Author="lowkey2046"
[MySQL]
Host="127.0.0.1"
Port=3306
Database="testdb"
Username="root"
Password="lowkey2046"
3. C++代码
mysqltoml.cpp 文件如下:
#include
#include "cpptoml.h"
struct MySQLArg{
std::string host;
int32_t port;
std::string database;
std::string username;
std::string password;
};
bool readMySQLConfig(const char *file, MySQLArg &mysqlArg);
int main(int argc, char **argv)
{
char filename[] = "./mysql.toml";
MySQLArg mysqlArg;
if (readMySQLConfig(filen