PDA

View Full Version : REALLY simple Xcode question! Input File Stream!




HolyKiwi
Mar 26, 2008, 02:28 PM
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
Mar 26, 2008, 02:31 PM
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
Mar 26, 2008, 02:40 PM
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
Mar 26, 2008, 03:21 PM
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
Mar 26, 2008, 04:31 PM
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
Oct 20, 2008, 04:15 PM
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
Oct 20, 2008, 05:39 PM
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.