I have written a program that can open and read a text document. I compiled the code with no errors but I am still not able to open the text document. I have checked that the location where the text file is kept has full access.The text file resides in inFile.open("C: \\Users\LJ\\Des ktop\\CPPExampl es\\Section4\\D elta_T\\Test01. txt"); where Delta_T is a folder. Please view my code.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inFile;
inFile.open("C: \\Users\LJ\\Des ktop\\CPPExampl es\\Section4\\D elta_T\\Test01. txt");
//Check for error
if (inFile.fail())
{
cout << "Error Opening File";
}
else{
string item;
// while(inFile >> item)
while(getline(i nFile, item))
{
cout << item << endl;
}
inFile.close();
}
system("pause") ;
}
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inFile;
inFile.open("C: \\Users\LJ\\Des ktop\\CPPExampl es\\Section4\\D elta_T\\Test01. txt");
//Check for error
if (inFile.fail())
{
cout << "Error Opening File";
}
else{
string item;
// while(inFile >> item)
while(getline(i nFile, item))
{
cout << item << endl;
}
inFile.close();
}
system("pause") ;
}
Comment