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

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
Use your Operating Systems "find" functionality to search for the file.

Yeah I did that but it the file doesn't show up. BTW, sorry if the names shocked you.
Do I need to add the directory when I create a file?

For example:

 
ofstream outputFile("user//documents//demofile.txt");
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
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.

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?
Possibly some kind of permissions problem. Also when working with an IDE the file may "appear" in some other directory.

Ok I see. Weird that it would appear in another directory though. Thanks.
Topic archived. No new replies allowed.