while and priming read

I am writing a loop that reads text from a file one char at a time and prints it to the screen. I don't think I understand how to code the priming read. I have used inFile.get twice is this unnecessary I thought you weren't supposed to repeat code twice. here is a snipet.It responds correctly but I feel as if I have extranious code. Any suggestions would be great:

ifstream inFile;


inFile.open ("austin.txt");
char ch;

inFile.get (ch);
cout << ch ;

while (inFile)
{
inFile.get (ch);
cout << ch;
}
inFile.clear ( ); // clear fail state
inFile.close ( );
Code in the form
1
2
3
4
5
s;
while ( c )
{
    s;
}
is equivalent to
1
2
3
4
5
do
{
    s;
}
while ( c );
Actually there is a subtle difference. If say c == 0 assume c is int. Then

s;
while (c)
{
s; //this line never get executed.
}

do
{
s; //this line is executed at least ONCE before the comparison take place at the bottom
} while (c);

So do-while will execute statement at least ONCE before the condition is checked whereas while will do the condition check FIRST before execute statement.

Thanks to everyone for the input:-)
@sohguanh
if you read carefully, s will be executed at least once in both cases
Hi thanks Bazzy, miss it out. Yes s will be executed at least once in both cases.
I see both executions thanks again
Topic archived. No new replies allowed.