XCode C++ Text File

Discussion in 'Mac Programming' started by thedude563855, Jul 1, 2010.

  1. thedude563855 macrumors newbie

    Mar 9, 2010
    Hey, so I'm new to C++ and XCode and I'm wondering why the following code won't work:

    #include <iostream>
    #include <fstream>

    using namespace std;

    int main (int argc, char * const argv[]) {
    ofstream file;
    file << 30;

    Nothing is being output to the file. If I replace the int 30 with a string "30", it works fine. Everything I can find online says that this should work, so I have no idea what the problem is. Thanks.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Works for me.

    Which version of OS and Xcode?

    When you say "nothing", do you mean no file is created, or the file is created but empty?

    How do you run the program?

    Where are you looking for the file? Is the program's working directory what you think it is?

    If unsure what your working directory is, add:
    #include <unistd.h>
    char buf[1024];
    cout << getcwd(buf,sizeof(buf)) << endl;

Share This Page