如何在 xcode 中使用标准的 c++ 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5149086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use standard c++ libraries in xcode?
提问by Haoest
I have a new empty xcode project. It gives me "No such file or directory" compile error when I try to import some c++ libraries such as <iostream>
, <string>
, and <map>
我有一个新的空 xcode 项目。当我尝试导入一些 C++ 库(例如、 和 )时<iostream>
,它给了我“没有这样的文件或目录”编译错误<string>
<map>
What do I have to do to import c++ libraries into xcode for so I can call their functions in objective-c?
我需要做什么才能将 c++ 库导入 xcode 以便我可以在 Objective-c 中调用它们的函数?
回答by Wolfsokta
If you are just trying to write C++ code in Xcode instead of calling C++ libraries in your objectiveC project you can create a C++ project. I just created a new project using the "Command Line Tool" template and selected C++ as the language.
如果您只是想在 Xcode 中编写 C++ 代码而不是在您的 ObjectiveC 项目中调用 C++ 库,您可以创建一个 C++ 项目。我刚刚使用“命令行工具”模板创建了一个新项目,并选择了 C++ 作为语言。
I could then add the following lines without the compiler complaining.
然后我可以添加以下几行而编译器不会抱怨。
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
To use items from the std c++ libraries you prefix them with std::
要使用 std C++ 库中的项目,请在它们前面加上 std::
int main (int argc, const char * argv[])
{
std::cout << "Hello World!";
return 0;
}
I was actually searching stack overflow for the reason std:: is necessary in Xcode...
我实际上是在搜索堆栈溢出,原因是 std:: 在 Xcode 中是必需的...