Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 8, 2007, 09:30 PM   #1
CaptainHat
macrumors newbie
 
Join Date: Mar 2007
xcode and input files

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.
CaptainHat is offline   0 Reply With Quote
Old Mar 8, 2007, 09:54 PM   #2
bbarnhart
macrumors 6502a
 
bbarnhart's Avatar
 
Join Date: Jan 2002
Location: Stilwell, Kansas
Send a message via Skype™ to bbarnhart
Does the filename need to be fully qualified?

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

Or, is "input.txt" in the same directory as the app?
bbarnhart is offline   0 Reply With Quote
Old Mar 8, 2007, 10:07 PM   #3
CaptainHat
Thread Starter
macrumors newbie
 
Join Date: Mar 2007
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.
CaptainHat is offline   0 Reply With Quote
Old Mar 8, 2007, 10:28 PM   #4
bbarnhart
macrumors 6502a
 
bbarnhart's Avatar
 
Join Date: Jan 2002
Location: Stilwell, Kansas
Send a message via Skype™ to bbarnhart
Quote:
Originally Posted by CaptainHat View Post
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"?
bbarnhart is offline   0 Reply With Quote
Old Mar 8, 2007, 10:54 PM   #5
lazydog
macrumors 6502a
 
Join Date: Sep 2005
Location: Cramlington, UK
Send a message via MSN to lazydog
Quote:
Originally Posted by CaptainHat View Post
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
lazydog is offline   0 Reply With Quote
Old Mar 10, 2007, 10:54 AM   #6
CaptainHat
Thread Starter
macrumors newbie
 
Join Date: Mar 2007
Thanks.
CaptainHat is offline   0 Reply With Quote
Old Mar 11, 2007, 08:23 AM   #7
Soulstorm
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
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.
Soulstorm is offline   0 Reply With Quote
Old Mar 11, 2007, 11:26 AM   #8
wittegijt
macrumors member
 
Join Date: Feb 2007
Location: Eindhoven
Quote:
Originally Posted by Soulstorm View Post
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
wittegijt is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Xcode build phase - unknown number of input files to unknown number of output files TheChekt Mac Programming 0 Dec 15, 2013 09:42 AM
Xcode 4.5.2 - Execution stops after CIN input Adrian00 Mac Programming 14 Dec 11, 2012 10:01 AM
Xcode C input Creck Mac Programming 3 Sep 23, 2012 05:31 AM
Input/Output with files in XCode crisro996 Mac Programming 2 Jul 21, 2012 01:20 PM
Code stops running in Xcode if input stream is long skatedate22 Mac Programming 6 Jul 10, 2012 04:44 AM

Forum Jump

All times are GMT -5. The time now is 09:13 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC