【问题标题】:Why is visual studio not recognizing is_open() function为什么 Visual Studio 无法识别 is_open() 函数
【发布时间】:2019-10-05 10:46:53
【问题描述】:
#include <fstream>
#include <string>

using namespace std;
void Readfile(string fname)
{
    ifstream infile(fname);
    if (is_open(infile))
    {
        while (!infile.eof())
        {
            string sline = "";
            getline(infile, sline);
        }
        infile.close();

    }
    else
        stderr << "unable to open file" << fname << endl;

}

Visual Studio 说标识符“is_open”未定义,即使我包含了 fstream 库。

【问题讨论】:

标签: c++


【解决方案1】:

is_open 是std::ifstream 的一个方法。使用infile 对象来调用它:

ifstream infile(fname);
if (infile.is_open())
{
   //....
}

【讨论】:

  • 比我快几秒!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-06
  • 2021-06-18
  • 2023-03-16
  • 1970-01-01
  • 2021-12-12
  • 2022-11-18
  • 1970-01-01
相关资源
最近更新 更多