Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
int main () {
	ifstream file ("C:\\Users\\filetypes.txt", ios::in|ios::binary|ios::ate);
	if (file.is_open())
	{
		size = file.tellg();
		memblock = new char [size];
		file.read (memblock, size);

		cout << "the complete file content is in memory";

		for (int l=0; l<size;>		{
			cout << " memblock[] is = " 
                             << (unsigned char)memblock[l] 
                             << " index was l = " << l << endl;

                }
        }		

}

using above code not am not getting the data.can any one check it please.
Posted
Updated 14-May-13 0:20am
v3
Comments
Jochen Arndt 14-May-13 6:24am    
I have added pre tags to the code block to improve readability.
However, you should fix the for statement (the code would not compile).

1 solution

You're opening the file with ios:ate so that the file pointer is at the end of the file, which is why tellg returns you the size you need. You then need to reset the pointer to the start of the file, using seekg, before you call read.
Regards,
Ian.
 
Share this answer
 
Comments
P Uday kishore 14-May-13 6:37am    
Its working by following that reset.Thank u...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900