View Full Version : How to use C++ <fstream> output files with Xcode?

Mar 1, 2012, 07:54 AM
I am learning C++ at school, but I have a Mac and I just started using Xcode. I use the fstream library.
I need to know where the ".out" file is located or how to create it.
I managed to create the input file and if I use "cout" to display the result it works. Hope I explained everything well, here is a very basic program to show you what I mean:

#include <fstream>
using namespace std;
int main()
int a,b;
ifstream in("test.in");
ofstream out("test.out");
out<<"a+b= "<<a+b;

Mar 1, 2012, 03:45 PM
Your code creates the output file. In this case, it will be created in the folder from which you run the program. If you are running it from within Xcode, you can set your working directory, or use the default. I'm not sure where the default location is.

Mar 1, 2012, 05:05 PM
This thread shows where to set the Working Directory in Xcode 4:

If you're not using Xcode 4, please identify your Xcode version.