1

I am making a game and I'm using the AppData\Roaming folder to store the file that contains the high score. I'm using the _dupenv_s() function to get the path to this folder.

However, on Linux the _dupenv_s() function throws an error: ā€˜_dupenv_s’ was not declared in this scope, even though the code is completely the same (other than \\ being converted to /, but that shouldn't matter).

I made sure to include all the necessary libraries such as <stdlib.h>, so that probably isn't the problem.

I could make different versions for Linux and Windows but I'd like the code to be the same for both operating systems.

Is there a way to get the path to AppData\Roaming or equivalent folder (e. g. ~/.local/) in C++?

  • When developing for multiple platforms. Create an abstract baseclass (interface) with methods that model WHAT you want to do (e.g. safe a temp file). And then provide different implementations on different platforms. Added bonus : you can inject mocks during unit tests (unit tests will be important for you when you are developing a big project like a game) – Pepijn Kramer May 28 '23 at 08:00
  • Here's an interesting discussion about proposing `file_system::home_directory()`: https://groups.google.com/a/isocpp.org/g/std-proposals/c/8zH7v7ow5bQ (TL;DR: No such propsal exists afaik) – Ted Lyngmo May 28 '23 at 08:28

0 Answers0