我在 Visual Studio 中并使用此代码(与 ofstream 相同)获得“ifstream 未声明的标识符”
#include <iostream>
#include <iomanip>
#include <fstream>
void main()
{
ifstream infile("file.txt");
ofstream outfile("out.txt");
}
我还需要添加其他内容吗?
最佳答案
您需要确定范围。使用 using namespace std;
或 ifstream
和 ostream
with std::
例如,std::ifstream
目前,编译器不知道这些结构在哪里定义(因为它们是在 std
命名空间中声明/定义的)。这就是为什么您需要在这种情况下确定您的结构/功能的范围。
关于C++ ifstream 未声明的标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5931971/