How to use C++ <fstream> output files with Xcode?

Discussion in 'Mac Programming' started by alexhutu, Mar 1, 2012.

  1. macrumors newbie

    Joined:
    Jan 28, 2012
    #1
    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");
    in>>a>>b;
    out<<"a+b= "<<a+b;
    }
     
  2. macrumors 65816

    Joined:
    Nov 26, 2007
    Location:
    Austin, TX
    #2
    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.
     
  3. macrumors 603

    Joined:
    Aug 9, 2009
    #3

Share This Page