Re: Problems with fstream
Re: Problems with fstream
- Subject: Re: Problems with fstream
- From: "Clark Cox" <email@hidden>
- Date: Mon, 9 Jun 2008 20:00:06 -0700
On Mon, Jun 9, 2008 at 7:41 PM, Jens Alfke <email@hidden> wrote:
>
> On 9 Jun '08, at 6:26 PM, Paulo Ferreira wrote:
>
>> I tried to chage the pontos.txt to pontos.cpp, but it didn't work =P ...
>> yes, the pontos.txt and pontos.cpp are in the project.
>> SO, does someone has any idea how to solve this problem?
>
>
> Your code is making the assumption that at runtime the current directory is
> set to the directory that pontos.txt is in. There's no reason this needs to
> be the case. You should be using absolute paths when opening files.
>
> If your target builds some type of bundle, then you should use CFBundle or
> NSBundle APIs to locate the resource file.
>
> If not (i.e. it's a command-line tool) then you have to take into account
Even if it doesn't build a bundle, the CFBundle/NSBundle APIs will
still to the right thing:
[ccox@ccox-macbook:~]% cat test.c
#import <CoreFoundation/CoreFoundation.h>
int main() {
CFBundleRef bundle = CFBundleGetMainBundle();
CFURLRef url = CFBundleCopyBundleURL(bundle);
CFStringRef path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
CFShow(path);
CFRelease(path);
CFRelease(url);
return 0;
}
[ccox@ccox-macbook:~]% cc test.c -framework CoreFoundation
[ccox@ccox-macbook:~]% ./a.out
/Volumes/Data/Home/ccox
[ccox@ccox-macbook:~]% pwd
/Volumes/Data/Home/ccox
--
Clark S. Cox III
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden