Reading from File in cocos2dx C++

Reading from File in cocos2dx C++


I read the below link for reading from a file and have a doubt.

The code for Android and Windows is same whereas the code for IOS differs in just one function.
The function getFilePath() is different for IOS.(Please refer the link)

Can the getFilePath() function be combined and written as follows:

  string FileOperation::getFilePath()
  string path("");

         // In android, every programe has a director under /data/data.
    	 // The path is /data/data/ + start activity package name.
         // You can save application specific data here.
         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,         NSUserDomainMask, YES);
    	NSString *documentsDirectory = [paths objectAtIndex:0];
        string path = [documentsDirectory UTF8String];
     	path.append( "/test.txt" );

    	// You can save file in anywhere if you have the permision.

    	path = cocos2d::CCApplication::sharedApplication().getAppDataPath();

   #ifdef _TRANZDA_VM_
      // If runs on WoPhone simulator, you should insert "D:/Work7" at the
          // begin. We will fix the bug in no far future.
     	path = "D:/Work7" + path;


return path;


Why is this the drive letter hard-coded in here? It would introduce major issues, if there is no drive letter D.


We have a bit of info on accessing the file system:

There shouldn’t be a need to do any Objective-C amongst your c++ for other platforms. We handle everything in a cross-platform manner.


Thank you for the link.

Is there a sample code for File I/O?

What if I have an XML file and want to read data from that XML File?


The link does not work.



I’ll add an nginx re-write rule.

Edit: actually the original link works for me…