Click to See Complete Forum and Search --> : Reading Text into a CStatic


Jason Coene
April 7th, 1999, 06:19 PM
Hello. I am attempting to read a standard ASCII text file into a CStatic.
So far, i use this type of method:

CViewDlg dlg;
CString szNfo;
FILE *f;
f = fopen("tt.txt", "r");
if(f == NULL)
{
MessageBox("Couldent open tt.txt!", "Error", MB_ICONERROR);
return;
}

byte buf[1];
while(fread(&buf[0],1,1,f))
{
CString na = "\r";
CString nb = "\n";
if(buf[0] == na)
szNfo+="\n";
else
szNfo += buf[0];
}
fclose(f);
dlg.m_szNfo = szNfo;
dlg.DoModal();

But when the CStatic comes up, it has the text, but all the line returns "\n" are replaced with Blocks! If you can give me some help i would be very appreciative.
thanks,
jason

April 8th, 1999, 05:40 AM
You should use CString strCrLf = CString( char(13) ) + CString( char(10) );
and use strCrLf instead of \n.