Advertisement

ifstream - read X bytes

Started by December 31, 2002 09:30 AM
1 comment, last by zackriggle 21 years, 10 months ago
How do I read X bytes from an Ifstream, without using getline()... because I want to be able to see the newlines... I think that I could just ifstream:eek() my way through the whole thing, and read bit-by-bit, but this seems somewhat slow... ================== My (soon-to-be) Cherished Cookie of Appreciation: -- MattB - for WinSock advice --
ifstream in(filename); //open filein >> noskipws;        //don''t skip whitespaceint numread=in.readsome(buffer,X) //read up to X bytes into buffer, not null terminated 
Advertisement
Data can be just about anything really, including a struct (and probably a class, but I think you''d need a copy constructor).

ifstream in(filename, ios::binary);
in.read((char *)&data, x); // x is the number of bytes to read
-YoshiXGXCX ''99

This topic is closed to new replies.

Advertisement