I have been trying to print the contents of a file, however, it will not print anything it will only return 0. I have checked and double checked my code and I can't find any reason as to why it won't work. Here is a sample of my code.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream infile("test.txt");
string line;
if(infile.is_open())
{
cout << infile.rdbuf();
}
else
{
cout << "error" << endl;
}
infile.close();
return 0;
}