Problem with reading bundle text file
Hi all,
I have some text files contain level data, i'm able to get the path of bundle file, but i couldn't success to read it in both objective-c or c++ ways.
Here is my code:
I have some text files contain level data, i'm able to get the path of bundle file, but i couldn't success to read it in both objective-c or c++ ways.

Here is my code:
Code:
- (void) loadLevel: (NSString*) levelFilename
{
NSString *filePath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:levelFilename];
const char *filename = [filePath UTF8String];
map->loadMap(filename, blocks);
/***** I'm new to objective-c, i copied this code from apple document *****
NSString *myText = [NSString stringWithContentsOfFile:filePath];
NSError *error;
NSString *myText = [[NSString alloc] initWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:&error];
NSLog(@"%@", myText); // it shows NULL here...
****************************************************************************/
}
// map.mm
void Map::loadMap(const char *filename, bool blocks[16][16])
{
cout << "Filename: " << filename << endl;
ifstream infile(filename);
if(infile.fail())
{
cout << "Error: " << filename << " can't open!" << endl;
exit(0);
}
string test;
while(getline(infile, test))
{
cout << test << endl;
}
infile.close();
}
Since you know where the problem is, inspect the file path you're getting back and check to see if your file is in that location.
Thanks for replied, i just checked the .app file, and my text file isn't there.
I added the text file in Resource folder already, how come it didn't bundle with the app?
Do i have to set anything?
I added the text file in Resource folder already, how come it didn't bundle with the app?
Do i have to set anything?
Check if it's actually in the Copy Resources build phase in the app Target.
i deleted the files and recopy them few times, and finally the problem is solved.
Thanks for all the replies!!
Thanks for all the replies!!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Reading a ".puz" file | tcIgnatius | 0 | 2,088 |
Jul 5, 2010 02:49 PM Last Post: tcIgnatius |
|
| Bundle Identifier used by another app | Bersaelor | 3 | 3,011 |
May 7, 2010 01:01 PM Last Post: Bersaelor |
|
| Save game state using Property list or Text File? | Graphic Ace | 2 | 3,223 |
Apr 6, 2009 03:48 AM Last Post: Graphic Ace |
|

