0
Input text file in C++
I have been trying to get my program to output text from my text resource file in Visual Studios, but for some reason, it never reads it. Can anyone help? This is what I have: #include <fstream> #include <iostream> #include <string> using namespace std; int main() { ifstream infile; infile.open("Try.txt"); //Check for error if (!infile.fail()) { cout << "Error Opening File"; } else { string W; while (getline(infile,W)) { cout << W << endl; } } infile.close(); system("pause"); return 0; }
2 Answers
+ 4
if(!infile.fail()) should be if(infile.fail())
0
It finally worked, thanks.