像这样的东西:
void Read::readFile()
{
FILE * fp = fopen(this->filename,"rt");
if (fp)
{
char *pData = NULL;
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
if (size != -1L)
{
pData = new char[size];
if (size > 0)
{
fseek(fp, 0, SEEK_SET);
size = fread(pData, sizeof(char), size, fp);
}
}
fclose(fp);
if (size < 0)
{
delete[] pData;
pData = NULL;
}
else if (size > 0)
{
char *start = pData;
char *end = start + size;
char *ptr = (char*) memchr(pData, '\n', size);
while (ptr)
{
int len = 1;
if ((ptr > start) && ((*ptr-1) == '\r'))
{
--ptr;
++len;
}
memmove(ptr, ptr+len, end - (ptr+len));
end -= len;
ptr = (char*) memchr(ptr, '\n', end - ptr);
}
size = (end - start);
}
this->data = pData;
this->size = size;
}
}