找不到“ iostream”文件Xcode

时间:2019-10-03 21:59:25

标签: c++ xcode c++11 io

每当我尝试使用Xcode 11生成C ++程序并输入以下行时:

class TwitterTabBare extends StatefulWidget {
  @override
  _TwitterTabBareState createState() => _TwitterTabBareState();
}

class _TwitterTabBareState extends State<TwitterTabBare>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 4, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    double screenHeight = MediaQuery.of(context).size.height;
    return column(
      children: <Widget>[
        TabBar(
          controller: _tabController,
          labelColor: Colors.blue,
          unselectedLabelColor: Colors.grey[700],
          tabs: <Widget>[
            Tab(
              text: 'Tweets',
            ),
            Tab(
              text: 'Replies',
            ),
            Tab(
              text: 'Media',
            ),
            Tab(
              text: 'Tweets',
            ),
          ],
        ),
        Container(
          constraints: BoxConstraints.expand(height: 300),
          child: TabBarView(
            controller: _tabController,
            children: <Widget>[
              // CardPage(),
              Column(
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),
                  Text('Tweets & replies'),

                ],
              ),
                  Text('Replies'),
                  Text('Media'),
                  Text('Likes'),
            ],
          ),
        ),
      ],
    );
  }
}

显示一条错误消息“找不到'iostream'文件。我正在使用的库是libc ++,而不是libstdc ++。

其他人似乎没有遇到此问题,所以我不知道发生了什么。

#include <iostream>

5 个答案:

答案 0 :(得分:2)

在将C ++类与Objective-C包装器一起使用时,我们遇到了相同的问题。

在检查构建命令时,我们发现Xcode传递了Objective-c作为clang的语言。将Wrapper文件扩展名更改为'.mm'时,XCode开始将语言作为Objective-C ++传递,并且错误消失了。

答案 1 :(得分:0)

我遇到了完全相同的问题。确实有lot个人这样做。我尝试重新安装Xcode,但错误仍然存​​在。唯一有用的是用brew update更新所有内容。

答案 2 :(得分:0)

我在终端中运行了以下命令:

xcode-select --install

在安装过程结束时,我退出并重新打开Xcode,问题消失了。

答案 3 :(得分:0)

尝试添加头文件路径:

构建设置->搜索路径->系统标题搜索路径

添加:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c ++ / v1 /

答案 4 :(得分:0)

我终于能够避免此错误,这就是我所做的。

  1. 打开终端并输入: EquipmentType
  2. 使用:
xcode-select --install

代替:

#include "/Library/Developer/CommandLineTools/usr/include/c++/v1/iostream"