Using STL in an iOS Application

Searching the net I couldn't find any tutorials that went one step before using STL in an iOS app. So, for example, if I wanted to use Vector in my desktop workclasses that don't interact with any Cocoa frameworks.

If someone could give me a simple "Hello world" equivalent for this, it would be much appreciated. Or point me to any tutorials they could find.

thank

+1


source to share


1 answer


Here's some sample code. Create a new ios project, set BuildSettings-> Apple LLVM Language-> Compile Sources Regarding "Objective-C ++". Open "ViewController.m" and add this line

#import "queue"

      

and put that in 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.

+1


source







All Articles