0

I am developing an iPad app with Xcode 4.6. In order to collect some critical information about the app, during the debug process (for real ios device) I put some data in a text file, and an example can be demonstrated with the following code:

   std::ofstream f;
    f.open("test.txt",std::ios::out ) ;
    for (int i=0;i<100;i++)
    {
        f << i << std::endl;
    }
    f.close() ;

After running the app, I want to examine the data in test.txt, however, I do not know how I can find it. This post seems to be helpful, but I cannot find the Application Data following his instruction.

Community
  • 1
  • 1
feelfree
  • 11,175
  • 20
  • 96
  • 167
  • 1
    Why don't you develop a proper logging class and use it throughout the lifetime of your app? – trojanfoe Oct 31 '13 at 11:50
  • @trojanfoe thanks for your comments, and it is a little complicated in my case. The data I collected will be treated as an input of another software package, and I will analyse the data then. – feelfree Oct 31 '13 at 11:53
  • Are you doing this on a real iOS device or the simulator? How you access the file depends on the answer. – rmaddy Oct 31 '13 at 14:09
  • @rmaddy I works on a real iOS device. – feelfree Oct 31 '13 at 14:19
  • What part of the instructions in your linked post don't you understand? Once you save the files, dig into the saved file for the desired sandbox files. – rmaddy Oct 31 '13 at 14:24

2 Answers2

1

Application Documents folder is accessible via iTunes. But for that you must enable File sharing for application. Here is a link for enabling file sharing https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/CoreServicesLayer/CoreServicesLayer.html#//apple_ref/doc/uid/TP40007898-CH10-SW30

but better use NSLogs or any other custom Logger.

Vishal Kardode
  • 961
  • 2
  • 8
  • 25
1

You will need to set the full path to the output file as by default the current working directory will be the app bundle directory, which you cannot write to (you aren't specifying a full path in your file open statement, so it will use the cwd).

So, if you want it to appear in the app's documents directory you'll need to get that using Objective-C (or Objective-C++) and pass that path to the C++ method you posted.

I would recommend using Objective-C++ to allow you to mix programming languages (change file extension to .mm):

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
std::string docDir = [paths[0] UTF8String];
std::ofstream f;
f.open(docDir + "/test.txt", std::ios::out);
for (int i=0;i<100;i++)
{
    f << i << std::endl;
}
f.close();
trojanfoe
  • 120,358
  • 21
  • 212
  • 242