This library support to load environment variables from a .env
file and read them like what .json
does but more simple!
- 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).
- Download ONLY
dotenv
folder (make sure that it containsdotenv.h
inside). Simple right? - 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?
- 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!
- 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.
- This library just include only a header file (
dotenv.h
)!
- Microsoft Windows 10
x64/x86
- Visual Studio platform
x64/x86
- C++ 17
ISO/IEC 14882
- 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.
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.
You can download the latest version here.