That code works properly in Visual Studio Community 2019, input txt file opens and get read by Visual Studio Community. When I try it in Visual Studio Code it doesn't work and returns "access denied". I need to use Visual Studio Code. Input file is in the executable's directory in case of Visual Studio Code and in the .cpp file directory in case of VS Community.
VS Community Screenshot and VS Code Screenshot
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream file;
string word;
file.open("input.txt");
getline(file, word);
if (file.is_open() == true)
cout << "access aproval" << endl;
else
cout << "access denied" << endl;
cout << word << endl;
}
CodePudding user response:
Try to give the full location of the file.
file.open("C\..\input.txt");