0
In c++, creating files is very simple, just include the fstream library and use
ofstream arquivo;
open file("variables.txt");
But 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. Only that there is a small problem in these cases, in each computer with linux the path to the desktop is different. In mine for example I could just do that:
iofstream arquivo;
arquivo.open("/home/silas/desktop/arquivo.txt");
But on another computer maybe:
iofstream arquivo;
arquivo.open("/home/lucas/desktop/arquivo.txt");
A possible solution could be to use the
system("whoami");
That writes the name of the user to the terminal, but I don’t 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 system user, this would help a lot.
Why don’t you use
~/desktop/arquivo.txt
?– lazyFox