所以我试图将一些 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/