Input from file output to screen

I am using #include<fstream> and using file data.txt as input:

ifstream in_stream;

in_stream.open("file9.txt");

How do I output all its contents (regardless if the contents are of type int, char, float etc.) to the screen? I am assuming there is no need for an "ofstream" since I am not outputting anything to a file.
A way is with a loop and getline
eg:
1
2
3
4
5
6
string line;
while (in_stream) // while in_stream is good
{
    getline ( in_stream, line ); //read a line
    cout << line; // print that line
}
Bazzy, thanks that seems to work if I want to print line by line from the txt file. I should have thought of using a loop...

What if I need to print out character by character and not line by line?
Do the same thing with in_stream.get(): cout << char ( in_stream.get() );
You need the conversion as get() returns an int
Topic archived. No new replies allowed.