Reputation: 402
Searching on the net I could not find any tutorials taking one through the steps to using the STL in an iOS app. So for instance, if I wanted to use a Vector in my app's back end worker classes which don't interact with any Cocoa structures.
If someone could perhaps give me a simple "Hello world" equivalent for this, that would be much appreciated. Or point me to any tutorials that they may have found.
Thanks
Upvotes: 1
Views: 4389
Reputation: 11357
Here is some sample code. Create a new ios project, set BuildSettings->Apple LLVM Language->Compile Sources As to "Objective-C++". Open "ViewController.m" and add this line
#import "queue"
and put this into the viewDidLoad.
typedef std::pair<int, int> P;
std::priority_queue<P> queue;
for (int i = 0; i < 10; ++i)
{
queue.push(P(rand(), i));
}
for (int i = 0; i < 10; ++i, queue.pop())
{
P p = queue.top();
printf("%u %u\n",p.first,p.second);
}
works for me.
Upvotes: 1