https://github.com/jaytwolab/getenvvalue-cpp
Get OS environment value (using c++17)
https://github.com/jaytwolab/getenvvalue-cpp
Last synced: 4 months ago
JSON representation
Get OS environment value (using c++17)
- Host: GitHub
- URL: https://github.com/jaytwolab/getenvvalue-cpp
- Owner: JayTwoLab
- License: mit
- Created: 2024-08-24T12:13:38.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-29T04:36:08.000Z (over 1 year ago)
- Last Synced: 2025-02-02T12:53:24.205Z (11 months ago)
- Language: C++
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# GetEnvValue-cpp
- Get environment value of OS.
- It uses only Modern C++ (C++17).
- How to install
- Just include ```GetEnvValue-cpp.h```
- Case of obtaining ```PATH``` variable
```cpp
#include "GetEnvValue-cpp.h"
int main() {
// get PATH
std::string envVarName = "PATH";
std::optional envVarValue = j2::getEnvVar(envVarName);
if (!envVarValue) {
std::cout << envVarName << " is not set.\n";
return 0;
}
#ifdef _WIN32
char delimiter = ';';
#elif __APPLE__
char delimiter = ':';
#elif __linux__
char delimiter = ':';
#else
std::cout << "Unknown platform." << std::endl;
return 0;
#endif
std::string path = envVarValue.value();
std::vector directories = j2::splitPath(path, delimiter);
for (const auto &dir : directories) {
std::cout << dir << std::endl;
}
return 0;
}
```
## License
- GetEnvValue-cpp is under MIT License.
- It's a part of jaytwo(j2) library.
- https://github.com/JayTwoLab/GetEnvValue-cpp