title: How to store preferences (and user settings) in a cross-platform application?
body: <p>I'm working on a GUI desktop application that should run natively on Windows, Mac OS X and Linux. What is the preferred way to store preferences in a cross-platform application? I'm using C++, but the question (and its answers) should be valid for any natively compiled language. (Solutions for dynamic languages and Java can be seen <a href="https://stackoverflow.com/questions/4488320/cross-platform-configuration-options-settings-preferences-defaults">here</a>.)</p>
  
  <p>My research so far tells me, that there are at least two strategies:<br />
  (A) Use the OS-specific API preferences functions.<br />
  (B) Store the preferences in a file within an appropriate (OS-specific) folder.</p>
  
  <p>Let's consider method (A): I assume <code>NSUserDefaults</code> is the correct method for Mac OS X. On Windows systems, I'd write to the registry via <code>RegOpenKeyEx</code>. But there arise some questions: Is there any comparable and portable Linux API for that? Is writing to the Windows registry really a future-proof solution?</p>
  
  <p>To keep things simple, I'm inclined to follow method (B). Thus I just have OS-specific code to get the appropriate directory where I can store my data in a format of my choice. On Windows, I've learned <code>SHGetFolderPath</code> (or <code>SHGetKnownFolderPath</code> for recent Windows systems) and <code>CSIDL_LOCAL_APPDATA</code> is the way to go. On Macs, the <code>NSSearchPathForDirectoriesInDomains</code> API call should do the same; it's an Objective-C API though making things more complicated. Finally, for the Linux version using <code>getenv("HOME")</code> (and <code>getpwuid()</code> as a fallback solution) seems to be recommend.</p>
  
  <p>To summarize my questions:<br />
  1. Are there any patterns considered as best-practice for this task?<br />
  2. Is there any C++ class abstracting all the dirty things like finding the correct folder away out there? (I came across <a href="http://doc.qt.digia.com/4.7/qsettings.html" rel="nofollow noreferrer">QSetting</a>, but I'm using FLTK and I don't want to change my GUI toolkit.)</p>
  
  <p><strong>Edit:</strong><br />
  By "preferences" I mean data that may be changed by the application and the user, e.g. a list of recent files, the preferred window size and so on.</p>