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

CaptainHat

macrumors newbie
Original poster
Mar 8, 2007
8
0
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

macrumors 6502a
Jan 16, 2002
824
1
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

macrumors newbie
Original poster
Mar 8, 2007
8
0
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

macrumors 6502a
Jan 16, 2002
824
1
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

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
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
 

Soulstorm

macrumors 68000
Feb 1, 2005
1,887
1
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

macrumors member
Feb 18, 2007
31
0
Eindhoven
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.