Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a program that gathers user input and outputs it to a file in a specific format. I can't seem to figure out where it outputs to. I'm using Code::Blocks with g++.

What I have tried:

I have looked all through the files, but cannot find the output file.
Posted
Updated 16-Sep-16 9:12am
Comments
[no name] 16-Sep-16 14:46pm    
And you somehow think that we would know? We can't possibly tell you what is going on in your code.

1 solution

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.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900