Where is the file located after I created and wrote to it?

Oct 7, 2016 at 8:38pm
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
Oct 7, 2016 at 8:40pm
Use your Operating Systems "find" functionality to search for the file.

Oct 7, 2016 at 8:46pm
Yeah I did that but it the file doesn't show up. BTW, sorry if the names shocked you.
Oct 7, 2016 at 8:58pm
Do I need to add the directory when I create a file?

For example:

 
ofstream outputFile("user//documents//demofile.txt");
Oct 7, 2016 at 9:07pm
closed account (LA48b7Xj)
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
Oct 7, 2016 at 9:21pm
Yeah I did that but it the file doesn't show up.

Then maybe the file wasn't created. Perhaps you should check that the file opening actually succeeded.

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.

Or perhaps the directory where your project files are located, perhaps somewhere else, or somewhere else, etc.

Oct 7, 2016 at 9:22pm
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
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
Ok I see. Weird that it would appear in another directory though. Thanks.
Topic archived. No new replies allowed.