Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 8, 2007, 08: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, 08: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, 09: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, 09: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, 09: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, 09:54 AM   #6
CaptainHat
Thread Starter
macrumors newbie
 
Join Date: Mar 2007
Thanks.
CaptainHat is offline   0 Reply With Quote
Old Mar 11, 2007, 07: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, 10: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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Xcode c++ - Input files on command line alexWoz Mac Programming 25 Mar 4, 2014 12:31 PM
Reading and writing files and storage locations xcode portreathbeach iPhone/iPad Programming 1 Apr 2, 2011 06:22 PM
C Question - Can't open an input file in Xcode? ocolange Mac Programming 7 Oct 31, 2010 08:11 PM
Xcode c++ input file directory palsword Mac Programming 0 Oct 23, 2008 12:07 PM
REALLY simple Xcode question! Input File Stream! HolyKiwi Mac Programming 6 Oct 20, 2008 05:39 PM


All times are GMT -5. The time now is 08:31 AM.

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

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