gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:56:00 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com