Skip to content

A simple C++ dotenv file reader for reading .env file in simplest way

License

Notifications You must be signed in to change notification settings

Harshfeudal-Projects/dotenv

 
 

Repository files navigation

Dotenv for C++

dotenv

This library support to load environment variables from a .env file and read them like what .json does but more simple!

Build status Release GitHub issues GitHub license
Discord GitHub stars GitHub forks

📝 About this repository

  • This project is owned by @harshfeudal. You can join my Discord server here!
  • This library can be used for many different projects, currently, this library is enough to make a C++ Discord bot using D++ for safety token reader (you can use .gitignore to ignore .env file).

🚨 Usage

  1. Download ONLY dotenv folder (make sure that it contains dotenv.h inside). Simple right?
  2. Include it in your project like this:

main.cpp

#include <dotenv/dotenv.h>
#include <iostream>

int main() {
    // Load your .env file
	dotenv::load(".env");

    // Read your .env variable
    const char* my_var = std::getenv("MY_VAR");

    // Read it!
    std::cout << "The variable is: " << my_var << std::endl;
}

Compare it to your .env file:

MY_VAR="Hello World!"

Done! Simple right?

✨ Library features

  1. Somehow you really want to skip line (or do whatever you want) like this:
The sentence is:
"Hello World"
    - Hello 2023 -

... so, with this library feature, to do this, you can just do like this in your .env file:

SENTENCE="\n\"Hello World\"\n\t- Hello 2023 -"

and it will work as expected!

  1. Or, you really want to make a comment like this:
TOKEN="WW91ckRpc2NvcmRCb3RUb2tlbg=="    # Your Discord bot token

With this library features, your comment will be ignored after the # mark! Comments begin where a # exists, so if your value contains a # please wrap it in quotes.

  1. This library just include only a header file (dotenv.h)!

👷 Support platform

  • Microsoft Windows 10 x64/x86
  • Visual Studio platform x64/x86
  • C++ 17 ISO/IEC 14882

🤝 Support me

  • Please leave me a star if you like it. Thank you very much!
  • You can probably help me develop this project too by DMing me on my Discord profile.

💎 Contribution and Pull Request

I'd probably glad to see if you have anything new to help and support me. To do that, please make one and before you do that, just make sure you've tested the code. I won't bite you if you do it wrong, but just make sure that you have to test it clearly before I merge it.

📚 Download

You can download the latest version here.

- © 2023 Harshfeudal. All rights reserved. -

About

A simple C++ dotenv file reader for reading .env file in simplest way

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 74.3%
  • CMake 15.5%
  • Lua 6.8%
  • Shell 3.4%