RunningPig RunningPig - 5 months ago 11
Linux Question

How to pass environment variable to C++ program in Unix

I recently wrote a C++ program that opens a file and reads it. If I want to run the program in Unix/Linux and the file name and path will be a environment variable. How can I achieve it?

Thank you.

Answer

Use getenv(char const *name) of the stdlib.h. Note, however, that environment variables are a quite unclean way to pass parameters.