在 iOS 应用中使用 STL [英] Using STL in iOS app
问题描述
在网上搜索我找不到任何教程,其中包含在 iOS 应用程序中使用 STL 的步骤.例如,如果我想在不与任何 Cocoa 结构交互的应用的后端工作类中使用 Vector.
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.
如果有人能给我一个简单的Hello world"等价物,我将不胜感激.或者向我指出他们可能找到的任何教程.
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.
谢谢
推荐答案
这里是一些示例代码.新建一个ios项目,设置BuildSettings->Apple LLVM Language->Compile Sources As为Objective-C++".打开ViewController.m"并添加这一行
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"
并将其放入 viewDidLoad.
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);
}
对我有用.
这篇关于在 iOS 应用中使用 STL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!