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 ( );
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.