C++ Xcode 4 infile question

Discussion in 'Mac Programming' started by Nickatron, Mar 21, 2011.

  1. Nickatron macrumors newbie

    Joined:
    Mar 21, 2011
    #1
    Hello,

    I am in an introductory c++ programming class, and my program uses infile to read a .txt file and uses cout to display the contents. The program works great, but I had to put my text file in users/home/library/developer/xcode/deriveddata/PPC_5-aksdjhgad/build/products/debug/

    That is a mouthful! Is there an easier way to include my textfile, or build my program in the same directory as my .cpp file?
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    I haven't downloaded XCode 4, but others have mentioned where to change the working directory in the settings. you may want to search the forums for XCode working directory or something like that.

    Alternately, you could just use g++ at the terminal and not have to worry about any of this IDE hootenanny that is more likely to get in your way than help you at this stage of the game. Learn how to program, don't learn how to program in XCode.

    -Lee
     
  3. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #3
    Links for both topics:

    http://forums.macrumors.com/showthread.php?t=1119349

    http://forums.macrumors.com/showthread.php?t=1090449

    B
     
  4. Nickatron thread starter macrumors newbie

    Joined:
    Mar 21, 2011
    #4
    Thanks, I found my answer in one of the above links. Xcode > Preferences > Locations > Build Location
     
  5. TastyCocoa macrumors newbie

    TastyCocoa

    Joined:
    Mar 21, 2011
    #5
    Alternatively you can use

    inFile.open(/users/yourname/desktop/yourinputfile.txt)
     
  6. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #6
    At the very least you need quotes around the filename? ;)

    Code:
    inFile.open("/users/yourname/desktop/yourinputfile.txt")
    don't you need mode flags too? http://www.cplusplus.com/reference/iostream/ifstream/open/

    B
     
  7. TastyCocoa macrumors newbie

    TastyCocoa

    Joined:
    Mar 21, 2011
    #7
    Doh!

    As I understand it you don't need a flag with ifstream - its already in there by default. You do if you use the more general fstream though.
     

Share This Page