即使在包含 std 命名空间之后,fstream 在 Visual Studio 2017 中也无法正常工作


#include <iostream>
#include <fstream>
#include "stdafx.h"
using namespace std;
int main() 
{
ofstream myfile;
myfile.open("example.txt");
myfile << "Writing this to a file.n";
myfile.close();
return 0;
}

我正在使用Visual Studio 2017尝试在c ++中进行基本文件处理,似乎无法使用类fstream

错误 - 严重性代码说明项目文件行抑制状态 错误 C2065 "myfile":未声明的标识符 CSV C:\用户\用户\源\存储库\CSV\CSV\CSV.cpp 11 错误 C2065 "流":未声明的标识符 CSV C:\用户\用户\源\存储库\CSV\CSV\CSV.cpp 8 错误 C2146 语法错误:标识符"myfile"之前缺少";" CSV C:\用户\用户\源\存储库\CSV\CSV\CSV

.cpp 8
错误 C2065 "myfile":未声明的标识符 CSV C:\用户\用户\源\存储库\CSV\CSV\CSV.cpp 8
错误 C2065 "myfile":未声明的标识符 CSV C:\用户\用户\源\存储库\CSV\CSV\CSV.cpp 9 错误 C2228 左侧的".open"必须具有类/结构/联合 CSV C:\用户\用户\源\存储库\CSV\CSV\CSV
.cpp 9
错误 C2065 "myfile":未声明的标识符 CSV C:\用户\用户\源\存储库\CSV\CSV\CSV.cpp 10
错误 C2228 左侧的".close"必须具有类/结构/联合 CSV C:\用户\用户\源\存储库\CSV\CSV\CSV.cpp 11

我该怎么办?

编译器会忽略#include "stdafx.h"之前的所有内容,因此将该行移动到其他包含指令上方。

最新更新