Click to See Complete Forum and Search --> : Reading in a file


Boom
September 1st, 1999, 02:16 AM
I'm new so bare with me...

I have to read in a file which comprises an 3 columns of numbers, an x a y and a firction. ie
60.5673 45.6723 3.5
etc

So I'm not sure how to start should I be looking at CFile to read the file in?!? Or can it be done through the Serialize function of an SDI application?!?

I think i'm confused about the difference between the two... Is Serialize for just for saving changes to a document?!? SO when a user minimises the view and then brings it back the contents(say a drawing app) are still there?!?

thanks in advance
Boom

cube01
September 1st, 1999, 02:25 AM
What do you mean by "reading in"? are you talkin' about displaying it in a veiw? if not, I would go with CFile...

Boom
September 1st, 1999, 02:50 AM
I need to read/load the numbers from an ASCII text file, into a data structure. From there I have to 1 display it prolly as a bitmap, then run an algorithm on it to create polygon outliones then display these. So I guess my question is to read in from a file into a data structure should I use CFile?!?

cube01
September 1st, 1999, 03:02 AM
yeah... go with CFile..
look in the help at CFile's class members fer help on that...

Dick de Jonge
September 1st, 1999, 05:15 AM
Hi, maybe this part of code can help yuo:

CString infoPath = m_Drive + "filename_and_path';
CString enter = "\r\n"; // linefeed/carriage return invoegen
CStdioFile file;

if (!file.Open (infoPath, CFile::modeRead))
{
AfxMessageBox ("Kan " + infoPath + " niet openen!");
m_text.SetWindowText ("");
}
else
{
CString buf, inhoud = "";
while (file.GetPosition() < file.GetLength())
{
file.ReadString (buf);
inhoud += (buf + enter);
}
m_text.SetWindowText (inhoud);
file.Close();
}


bye, Dick