Objective C 和一些 C++代码无法编译
我有一个带有一些 C++ 代码的 Objective C 项目,当然 C++ 代码不会编译
我知道编译器会假设要编译哪种语言,但我之前见过这个应用程序运行,所以我很好奇如何使我的Xcode 4 运行编译这个项目
,即。此函数声明会产生错误,因为编译器无法识别 c++ std::
语法
std::string string_with_formatting(const unsigned int value)
{
我该如何解决此问题?我应该有什么 #include 或 #import
I have an Objective C project with some C++ code, and sure enough the C++ code won't compile
I understand that the compiler makes assumptions about which language to compile, but I have seen this app running before so I am curious how to make my Xcode 4 run compile this project
ie. This function declaration produces an error as the compiler does not recognize the c++ std::
syntax
std::string string_with_formatting(const unsigned int value)
{
How do I get around this? What #include or #import should I have
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Objective-C++ 是 C++ 的超集。您可以在 Objective-C++ 源代码中使用 C++。
.mm
扩展名,否则它将被视为 Obj-C,而不是 Obj-C++#include
Objective-C++ is a superset of C++. You can use C++ in Objective-C++ sources.
.mm
extension, otherwise it will be treated as Obj-C, not Obj-C++#include <string>
将该文件更改为
.mm
以及包含该文件的任何其他文件(或伴随.h
的文件)。Change that file to
.mm
and also any other that includes that file (or that files accompanying.h
).Objective C 没有 std::string 的概念。您需要使用类似
NSString
objective C has no concept of std::string. You need to use something like
NSString