Outputting contents of text file to screen.
Hi,
Just a quick C++ problem. Trying to open a text file and output the contents to the screen. Seemingly an easy task, but I can't find a good example on the net anywhere :(
My code is:
Code:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
ifstream ins;
string word;
char c;
// Open up the text file and read the data.
// Print and error if we can't open it.
ins.open("data.txt");
if(ins.fail())
{
cout << "Cannot read file." << endl;
return 0;
}
while (ins >> word)
{
ins.get(c);
cout << c;
}
}
It compiles and executes, however it doesn't print anything to the screen. I know I have done something really stupid, however I don't have a clue what it is.