'fstream doesn't read the input Visual Studio Code but it works in Visual Studio Community
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;
}
Solution 1:[1]
Try to give the full location of the file.
file.open("C\..\input.txt");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Skerdi Velo |
