c++ - include <iostream> 在 ViewController.h 中有效,但在 appDelegate.h 中无效

标签 c++ objective-c xcode objective-c++

所以我试图将一些 C++ 对象从我的 viewController.h 和 .mm 移动到我的 appDelegate.h 和 .mm。问题是我遇到一个预处理器问题,指出例如找不到,字符串也找不到。我尝试将文件类型更改为 Objective-C++ header ,但仍然出现错误,如果我尝试在 viewController.h 中使用#include,则不会出现此类错误。我如何在 appDelegate 中导入 C++?

//  AppDelegate.h

#import <UIKit/UIKit.h>
#include <iostream> // <-"'iostream' file not found"


@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

以及 viewController 的工作案例:

//  ViewController.h

#import <UIKit/UIKit.h>
#include <iostream>


@interface ViewController : UIViewController

@end

最佳答案

“AppDelegate.h”也包含在“main.m”中。将该文件重命名为“main.mm”应该可以解决 问题。

如果公共(public)接口(interface)“AppDelegate.h”不需要“iostream”,你应该 或者考虑将该文件仅包含在实现文件“AppDelegate.mm”中, 这也能解决问题。

关于c++ - include <iostream> 在 ViewController.h 中有效,但在 appDelegate.h 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16142893/

相关文章:

c++ - QPrintDialog 本地化

c++ - 避免 dynamic_cast 向下转换为原始类型

c++ - 用于在 QLabel 上对齐非恒定宽度文本的通用代码

c++ - 使用 std::async() 和 std::move() 将数据异步传递给另一个线程

ios - 将单元测试目标添加到现有 Xcode 项目,无法在 bundle 中找到资源

iOS ReactNative React 依赖问题

XCode 4.2 停止界面构建器自动缩放

iPhone:将副本上的资源重命名为 bundle ?

ios - 您已授权facebook、iOS

ios - 如何在 iOS 中设置自定义日期格式?