I want to do a program in C++ that, when is executed (from anywhere), modifies a text file in a very specific path (and always the same one). To do so, I've defined the following function in C++:
void ChangeCourse(string course)
{
ofstream active_course;
active_course.open("~/.universidad/curso_activo.txt");
if (!curso_activo)
cout << "Error: cant't open the file" << endl;
else
{
active_course << course;
curso_activo.close();
}
}
When executing the program that calls the function, I get the message Error: cant't open the file
and, indeed, no file is created.
How do I have to define the path of the file such a way the program could read it and find it, regardless of where the program was called.
Note that I'm running the program in macOS.
Hope I've explained my self and thank you in advance.