Say you have a program you run, and it has the following lines of code:
#include <fstream>
using std::fstream;
int main() {
fstream someFile;
someFile.open("~/someFile");
if(!someFile.is_open()) {
// Make the file
}
}
I'm trying to open a file in the home directory (i.e. "~" on Unix devices). How could this be done? What I'm doing right now doesn't seem to work. Additionally, how can I make the file if it doesn't exist yet?
Note that this program can run from anywhere; not just home, but I need it to look for a file in the home directory.