C++ ifstream 未声明的标识符

标签 c++ visual-studio

我在 Visual Studio 中并使用此代码(与 ofstream 相同)获得“ifstream 未声明的标识符”

#include <iostream>
#include <iomanip>
#include <fstream>
void main()
{
    ifstream infile("file.txt");
    ofstream outfile("out.txt");
}

我还需要添加其他内容吗?

最佳答案

您需要确定范围。使用 using namespace std;ifstreamostream with std::

例如,std::ifstream

目前,编译器不知道这些结构在哪里定义(因为它们是在 std 命名空间中声明/定义的)。这就是为什么您需要在这种情况下确定您的结构/功能的范围。

关于C++ ifstream 未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5931971/

相关文章:

c++ - 子类怎么调用父类初始化成员变量的构造函数不同呢? [C++]

c++ - native 代码 : cannot use typeid with -fno-rtti

c++ - 为 64 位 Linux 的特定 arm 目标交叉编译 Qt

c# - 如何让我的 Visual Studio 看起来像这样?

c++ - 在 vector 中存储不同维度的数组

c# - 通过 Ajax 发布到 MVC Controller

visual-studio - 如何使用.NET Core类库(.NET Standard)连接SQL Server数据库?

c++ - 关于使用#pragma region 在 Visual Studio 中折叠代码块

visual-studio - 如何在不停止进程的情况下停止调试(或分离进程)?

c++ - 如何在opencv的Aruco标记上绘制矩形?