Reputation: 45931
I'm developing an iOS application with latest SDK and I'm also using OpenCV.
I have some C++ classes and I have to read the content of a XML with these C++ classes.
With Objective-C I do it in this way:
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"xml"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
if (myData) {
// do something useful
}
But, how can I do it from C++?
I know that cpp need a file path and I don't know how can I get that path from C++.
All my OpenCV algorithms are in C++ classes, so I have to do it in those C++ classes.
Upvotes: 0
Views: 1599
Reputation: 4092
You have two options:
[filePath fileSystemRepresentation]
returns const char*
)[myData bytes]
and [myData length
])Upvotes: 1
Reputation: 122391
While it's, of course, possible to open the XML file and parse it using pure C++, I think you should use Apples-provided Objective-C classes to perform this parsing. You can do this by using Objective-C++ (i.e. mixed Objective-C and C++) simply by renaming your C++ implementation file extension from .cpp
to .mm
.
The reason I think this is a good idea:
plist
format, you will get those changes for free.Upvotes: 1