文本文件未在Visual Studio 2017上打开.它在Dev C++上打开


#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "string"
using namespace std;
int main()
{
fstream room_type;
string line;
room_type.open("rooms.txt", ios::in);
while (!room_type.eof())
{
getline(room_type, line);
cout << line << endl;
}
room_type.close();
}

我试着给出路径。我已尝试将.cpp文件和.text文件保存在同一位置。我已经尽我所能用我的知识+谷歌搜索了很多。没有什么能解决这个问题。

请添加上述文件所在的目录:

room_type.open("C:\which_directory\rooms.txt", ios::in);

您可以在不提及目录的情况下运行它,但在这种情况下,可执行文件应该与文件本身位于同一目录中,这可能取决于您的开发环境。

最新更新