In c ++, creating files is very simple, just include the fstream library and use
ofstream arquivo;
file.open ("variables.txt");
However this generates the file in the project folder and I would like to generate the file in some other folder, such as Desktop for example. But there is a small problem in these cases, on each computer with linux the path to the desktop is different. In my for example I could simply do this:
iofstream arquivo;
arquivo.open("/home/silas/desktop/arquivo.txt");
But on another computer it might be:
iofstream arquivo;
arquivo.open("/home/lucas/desktop/arquivo.txt");
One possible solution could be to use
system("whoami");
It writes in the terminal the name of the user, however I do not know any way to put the result of the command to a string. So, is there any way to do this? Or at least some function that returns the user of the system, that would help a lot.