c++ - 为什么 Visual Studio 无法识别 is_open() 函数
问题描述
#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 库。
解决方案
is_open
是一种方法std::ifstream
。使用infile
对象来调用它:
ifstream infile(fname);
if (infile.is_open())
{
//....
}
推荐阅读
- reactjs - 如何修改我的模态以便在 reactjs 中以不同的方式显示不同的项目?
- python - 使用 Scrapy 将网站中的新数据提取到现有表中
- gatling - 如何在 gatling 中找到 api 断点
- javascript - jQuery - 禁用自我并启用另一个的两个链接事件
- spring - 有没有办法在另一个项目中重用来自多个项目的黄瓜步骤?
- kotlin - Kotlin 中的 Float.isNaN“接收器类型不匹配”错误
- javascript - 忽略正则表达式中的模式中的一个词
- html - 使用 HTML 和 CSS 修复按钮动画
- javascript - Discord.js 获取分片 ID
- javascript - vue如何在v-if中获取元素上的元素引用