Thursday, July 9, 2009

C++ Programming?

Write a program that prints the numerical value of EOF.





I do not even know what EOF's numeric value is equal too. I think it is equal to -1, but a lot of texts and sites say other numbers too. I also know that EOF stands for end-of-file. Could someone help me to write this program!! I need it to end with:


printf(The numeric value of EOF is: %d\n", EOF);

C++ Programming?
You did 90% of the work! EOF can be different on various systems but is almost always -1 and is defined in stdio.h. Normally iostream will pull in stdio.h via some combo of headers but if your system doesn't then just include it.





#include %26lt;iostream%26gt;


//#include %26lt;stdio.h%26gt;





using namespace std;








int main()


{


printf("The numeric value of EOF is: %d\n", EOF);





cout %26lt;%26lt; "The numeric value of EOF is: " %26lt;%26lt; EOF %26lt;%26lt; endl;


}
Reply:try to do this to find the value of EOF





ifstream fin(FILENAME);





cout %26lt;%26lt; fin.eof() %26lt;%26lt; endl;





i think that it returns 1 for end of file and 0 for not end of file but im not sure. i use it in while loops all the time....





while(!fin.eof()){


}


No comments:

Post a Comment