Thursday, July 9, 2009

C++ help .............?

I intitialize an array of 100 elements of integer type which reads data from a file but file has only 10 elements what should be the condition of while statement that terminate after the 10th element


like


while(index%26lt;100 %26amp;%26amp; ???)


plz help me

C++ help .............?
There are multiple ways to do this. Here are two ways:





1)





ifstream inFile;


int array[100];


index = 0;





inFile.open("file.txt");





while(index %26lt; 100 %26amp;%26amp; inFile %26gt;%26gt; array[index])


{


index++;


}








2)





ifstream inFile;


int array[100];


index = 0;





inFile.open("file.txt");





while(index %26lt; 100 %26amp;%26amp; !inFile.eof())


{


inFile %26gt;%26gt; array[index];


index++;


}





// I hope this helps
Reply:FILE fp;








while(index%26lt;100 %26amp;%26amp; feof(fp))
Reply:NOT EOF





or maybe !EOF
Reply:why dont u use loop?


No comments:

Post a Comment