使用 ifstream 出现不完整类型编译器错误 [已关闭]

问题描述 投票:0回答:1

我试图通过打开文件并检查其是否打开来检查配置文件是否存在,但这不起作用。

这就是我所拥有的和错误

 if (!std::ifstream{"option.config"}.is_open()) {
    // create new config file
  }
<source>:184:31: error: invalid use of incomplete type 'std::ifstream' {aka 'class std::basic_ifstream<char>'}
  184 |   if (std::ifstream{"option.config"}.is_open()) {
      |   

请帮助我。我不知道这意味着什么

c++ file ifstream
1个回答
4
投票

您缺少 include for ifstream:

#include <fstream>

仅供参考,有更好的方法来检查文件是否存在:

© www.soinside.com 2019 - 2024. All rights reserved.