Oct 7, 2016 at 8:38pm UTC
I would like to open demo file.txt but I don't know where it is saved on my computer. Where is it located?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char * argv[])
{
ofstream outputFile("demofile.txt" );
cout << "Now writing data to the file.\n" ;
//Write 4 names to the file.
outputFile << "Marky.\n" ;
outputFile << "Gaylord.\n" ;
outputFile << "Etika.\n" ;
outputFile << "PussyLips.\n" ;
//Close the file.
outputFile.close();
cout << "Finito.\n" ;
return 0;
}
Last edited on Oct 7, 2016 at 8:46pm UTC
Oct 7, 2016 at 8:40pm UTC
Use your Operating Systems "find" functionality to search for the file.
Oct 7, 2016 at 8:46pm UTC
Yeah I did that but it the file doesn't show up. BTW, sorry if the names shocked you.
Oct 7, 2016 at 9:07pm UTC
It is created in the same directory that the program is run, if you are running it in a IDE maybe it is in the directory where your source files are.
Last edited on Oct 7, 2016 at 9:08pm UTC
Oct 7, 2016 at 9:22pm UTC
The file appeared in the directory where the source files are located after I compiled and ran the program on terminal. I wonder why the file didn't show up after I built and ran it on Xcode though. Does anyone know why?
Oct 7, 2016 at 9:56pm UTC
Possibly some kind of permissions problem. Also when working with an IDE the file may "appear" in some other directory.
Oct 7, 2016 at 10:14pm UTC
Ok I see. Weird that it would appear in another directory though. Thanks.