Checking binary file for a string
Posted on 2002-04-23
Hi Guys I an trying to read in a binary file to a variable called buffer.
See code below
buffer is defined as char *
but when I debug code, buffer only seems to hold the first character from the file.
What I am trying to achieve is to read in the file search it for a particular string and when I find this string, read in the entry in the file which is x characters after the first found string
I know 'seekg' can read in characters from a given position.... but firstly I have to find the position of a particular string in the file.
The file is an SQL Server Profiler trace file.
Is there some other way I can do this - Is there any way I can serach the file without reading it in... or do I need to declare buffer in a different way.
Any ideas would be appreciated
// readbinaryfile.cpp : Defines the entry point for the console application.
const char * filename = "C:\TenforeFeed.trc";
char * buffer;
char * pch;
int main(int argc, char* argv)
ifstream file (filename, ios::in|ios::binary|ios::ate);
size = file.tellg();
file.seekg (0, ios::beg);
buffer = new char [size];
file.read (buffer, size);
cout << buffer;