atari
asked on
What is the best way to read text files ?
Asked that question long times ago,
and got the answer to do it with CStdioFile something like this:
CStdioFile file;
if(!file.Open(log_file_nam e,CFile::m odeRead|CF ile::typeT ext)) return;
TCHAR buffer[1024];
while (file.ReadString(buffer,10 24)!=0);
file.Close();
But there is always a very disturbing \n linefeed-sign at the end of each line.
So I tried it with CArchive::ReadString something like this:
char txt[SDR_MAXTXT];
if (ar.ReadString(txt,count)! =NULL);
and so on, but with some texts I got problem, ReadString returned an error.
So is there a more easier way to read text files, that I didn't know and that I should try ?
Thanks,
bye,
atari
and got the answer to do it with CStdioFile something like this:
CStdioFile file;
if(!file.Open(log_file_nam
TCHAR buffer[1024];
while (file.ReadString(buffer,10
file.Close();
But there is always a very disturbing \n linefeed-sign at the end of each line.
So I tried it with CArchive::ReadString something like this:
char txt[SDR_MAXTXT];
if (ar.ReadString(txt,count)!
and so on, but with some texts I got problem, ReadString returned an error.
So is there a more easier way to read text files, that I didn't know and that I should try ?
Thanks,
bye,
atari
ASKER
Sorry, I have implemented something like this:
char *CutReadString(char *buffer)
{
int string_length=strlen(buffe r);
if (buffer[string_length-1]== '\n')
buffer[string_length-1]='\ 0';
return buffer;
}
but I think, it is rather slow to read large text files only this way. Maybe there is another solution for reading large text files, that is faster than the CStdioFile::ReadString-met hod ?
char *CutReadString(char *buffer)
{
int string_length=strlen(buffe
if (buffer[string_length-1]==
buffer[string_length-1]='\
return buffer;
}
but I think, it is rather slow to read large text files only this way. Maybe there is another solution for reading large text files, that is faster than the CStdioFile::ReadString-met
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
I don't know why I implemented the ReadString-function with a buffer, but with a CString it also works and has no \n at the end of the string. Maybe it was the cause, that I was new in MFC when I wrote this and there was an example in online-help:
// example for CStdioFile::ReadString
extern CStdioFile f;
char buf[100];
f.ReadString( buf, 99 );
so I implemented it with a buffer.
Thanks for your help.
Bye atari
I don't know why I implemented the ReadString-function with a buffer, but with a CString it also works and has no \n at the end of the string. Maybe it was the cause, that I was new in MFC when I wrote this and there was an example in online-help:
// example for CStdioFile::ReadString
extern CStdioFile f;
char buf[100];
f.ReadString( buf, 99 );
so I implemented it with a buffer.
Thanks for your help.
Bye atari
ASKER
Hi,
I don't know why I implemented the ReadString-function with a buffer, but with a CString it also works and has no \n at the end of the string. Maybe it was the cause, that I was new in MFC when I wrote this and there was an example in online-help:
// example for CStdioFile::ReadString
extern CStdioFile f;
char buf[100];
f.ReadString( buf, 99 );
so I implemented it with a buffer.
Thanks for your help.
Bye atari
I don't know why I implemented the ReadString-function with a buffer, but with a CString it also works and has no \n at the end of the string. Maybe it was the cause, that I was new in MFC when I wrote this and there was an example in online-help:
// example for CStdioFile::ReadString
extern CStdioFile f;
char buf[100];
f.ReadString( buf, 99 );
so I implemented it with a buffer.
Thanks for your help.
Bye atari
int iLFPos=csLine.ReverseFind(
if (iLFPos>=0)
csLine=csLine.Left(iLFPos)
in the CStdioFile solution after reading the line ?