Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

HolyKiwi

macrumors newbie
Original poster
Mar 26, 2008
1
0
I'm a comp sci major in college, and our default programming at school/home online console has got to be around 15+ years old now. I was tired of using it due to extreme lag... and started using XCode.

I'm past learning how to open files with C++, but our current assignment requires that one be open. What do I need to do to the file in XCode/Where do I need to put it so that my program can open it? Does it have to be in a specific folder or anything?

The file to be opened is Inventory.txt, and it's in the exact same folder as all the other .cpp and .h files. My coding for opening the program is flawless, as it works on the school's remote desktop'd unix, but at home I get the standard "Cannot open Inventory.txt!" that I added.

I'm using C++ Tool under command line utility.
 

ruckus

macrumors regular
Oct 19, 2005
180
0
hmmm. I don't have a lot of experience developing on a mac. But, maybe its a permissions issue? Make sure your program will have permission to the file, maybe just chmod 777 it from the terminal.

I would think if the file is with the compiled code (which may be in a different place than your source files) it should be able to open it otherwise.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
If you don't have an explicit path to the file, then it will look in the working directory of the program. I'm not sure what directory Xcode executes your program from, but it may be in some sort of build directory. There are probably options for that in the project setup.

-Lee
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
The directory that will be used depends on your Build setting. If you have Debug set, the default working directory is

/.../project_name/Build/Debug/.

If your setting is release, it will be

/.../project_name/Build/Release

Todd
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
Hi

Select your program under Executables in Groups & Files and then get info (cmd I). You'll see where the default directory is set to, or you can change it to what you want.

b e n
 

hokasu

macrumors newbie
Sep 28, 2008
4
0
Any success?

I'm in a similar situation, and wherever I place the input text file and however I fiddle with the working directory setting for the app, it seems to make no difference. Very odd. It looks like "Users/.." for ever:confused:
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,565
I'm in a similar situation, and wherever I place the input text file and however I fiddle with the working directory setting for the app, it seems to make no difference. Very odd. It looks like "Users/.." for ever:confused:

Try a full path, like "/Users/yourname/whatever". The "/" at the beginning would be important.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.