PDA

View Full Version : xcode and input files




CaptainHat
Mar 8, 2007, 08:30 PM
Hi,

I am trying to get a C++ tool to just read an input file and I added the file to the project, but whenever I try to open the file with

ifstream infile( "input.txt" );

it fails to open correctly. i.e., infile evaluates to false.

Ideas anyone?

thanks much.



bbarnhart
Mar 8, 2007, 08:54 PM
Does the filename need to be fully qualified?

"/Users/CaptainHat/Documents/input.txt"

Or, is "input.txt" in the same directory as the app?

CaptainHat
Mar 8, 2007, 09:07 PM
i just had "input.txt" , I copied the line from the source file into the original post.

I ended up giving the thing an explicit complete path, "/Users/.../input.txt" and this ended up working, but it's kind of annoying in any event.

Does anyone know how to set up Xcode so that if will look for input files in the same directory as the source code? This would a useful thing to know. I tried looking at the Build options in the help but this wasn't so easy to get through.

Thanks.

bbarnhart
Mar 8, 2007, 09:28 PM
i just had "input.txt" , I copied the line from the source file into the original post.

I ended up giving the thing an explicit complete path, "/Users/.../input.txt" and this ended up working, but it's kind of annoying in any event.

Does anyone know how to set up Xcode so that if will look for input files in the same directory as the source code? This would a useful thing to know. I tried looking at the Build options in the help but this wasn't so easy to get through.

Thanks.

"./input.txt"?

lazydog
Mar 8, 2007, 09:54 PM
Does anyone know how to set up Xcode so that if will look for input files in the same directory as the source code? This would a useful thing to know. I tried looking at the Build options in the help but this wasn't so easy to get through.

Thanks.

You can set the working directory for your executable in the 'General' tab in the info window for the executable. To get this window select 'Edit Active Executable' under 'Projects' in the menu bar. Just set it to whatever you want.

b e n

CaptainHat
Mar 10, 2007, 09:54 AM
Thanks.

Soulstorm
Mar 11, 2007, 07:23 AM
You can also change the current working directory using C++ itself. You should use the system() command to do that. And then, give inside the command whatever you would give inside a terminal shell to change the current working directory.

wittegijt
Mar 11, 2007, 10:26 AM
You can also change the current working directory using C++ itself. You should use the system() command to do that. And then, give inside the command whatever you would give inside a terminal shell to change the current working directory.

Or directly using chdir (const char *filename) :)

Wittegijt