ifstream binary file reading

Hi!
Im new to cpp, and i have problem with reading binary file
My code is:
1
2
3
4
5
6
7
8
	std::ifstream ifs(L"c:\\james.rar");
	char buff[1000];
	ifs.seekg (0, std::ios::beg);
	int count = 0;
	while(!ifs.eof()) {
		ifs.getline(buff, 1000);
		std::cout << count++ << std::endl;
	}


code stops at first iteration :( whats wrong with my code ? i cant read this file with one "read" call because its too big, so i need to read with buff to send via ethernet.

Thanks!
oh... made changes to code
 
std::ifstream ifs(L"c:\\james.rar", std::ios::binary);

so now my while never stops :) lol... how to check eof in binary mode ? My OS is Win XP.
this is the only way to find eof in any file. eof gives correct results for binary stream also..
this should not happen..code also looks fine..

what you can try is stop fetching data when the getline function returns empty string.
strange, but when i change getline to read it work fine:
1
2
3
4
5
6
7
8
	std::ifstream ifs(L"c:\\james.rar", std::ios::binary);
	char buff[1000];
	ifs.seekg (0, std::ios::beg);
	int count = 0;
	while(!ifs.eof()) {
		ifs.read(buff, 1000);
		std::cout << count++ << std::endl;
	}


Tanks for help!
Read in your case is storing the first 1000 characters into the buffer buff. It is performing the same thing as a getline statement in a sense.

Also read and write are used for binary i/o I don't know if getline will handle binary code.
Last edited on
strange..!!
Topic archived. No new replies allowed.