When you open a stream to a file, you pass the location of the file (including the name) to that object. Typically, a name of the file is passed only (like,
_ofstream.open("file.txt")
) which creates the file in the same directory, where the program is residing. In most cases, you would require to pass a full path. So for example if following is your program,
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream _filestream;
_filestream.open("file.txt");
_filestream << "Hello world!" << endl;
}
Then you will get a new file
created, inside the same directory (because the path is not qualified with the directory where it must go etc.). Otherwise, you might require to pass full path. Which would be,
1. "C:\MyData\File.txt" on Windows -- provided enough permissions are granted.
2. "/home/afzaal/Documents/file.txt" on Linux environments -- permissions
may be asked.
Read the code. That code has the answer. For more references, please read:
ofstream - C++ Reference[
^],
ofstream::open - C++ Reference[
^]. Open is the function responsible for opening the streams where the data is written at.