我正在尝试使用freopen()
打印到两个不同的文件。可能吗?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent: @"sensordata.txt"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:docDir])
{
[fileManager createFileAtPath:docFile contents:nil
attributes:nil];
}
freopen([docFile cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
NSLog(@"GyroData: %f %f %f ",gyroData.rotationRate.x, gyroData.rotationRate.y, gyroData.rotationRate.z);
NSLog(@"DeviceMotion: %f ",magnitude);
第二个 NSLog (DeviceMotion...) 应该保存在另一个文件中。
任何想法?谢谢