0

Is there a way to expand environment variables in a path? For example:

std::string myPath = expandEnv("$SOME_VAR/dir/")

So that when myPath is printed it contains the absolute path that would result from expanding $SOME_VAR ? I remember seeing this done somewhere, or might have implemented it myself, but I can't remember where.

I know Windows have it, is there anything in C++ STL, Boost or Linux headers that does that?

ventsyv
  • 3,316
  • 3
  • 27
  • 49
  • 1
    ["Simple and portable" - as noted by the user.](http://stackoverflow.com/a/20715800/4766989) First result on google... – Patrick Apr 14 '15 at 23:43
  • 1
    http://stackoverflow.com/questions/17112494/how-to-expand-environment-variables-in-ini-files-using-boost/17128601?s=13|0.0000#17128601 – sehe Apr 14 '15 at 23:45

1 Answers1

0

I ended up writing a regex and then expanded the matches

ventsyv
  • 3,316
  • 3
  • 27
  • 49