CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 1999
    Location
    Australia
    Posts
    17

    Reading in a file

    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


  2. #2
    Join Date
    Jul 1999
    Posts
    535

    Re: Reading in a file

    What do you mean by "reading in"? are you talkin' about displaying it in a veiw? if not, I would go with CFile...


  3. #3
    Join Date
    Aug 1999
    Location
    Australia
    Posts
    17

    Re: Reading in a file

    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?!?


  4. #4
    Join Date
    Jul 1999
    Posts
    535

    Re: Reading in a file

    yeah... go with CFile..
    look in the help at CFile's class members fer help on that...


  5. #5
    Join Date
    Jun 1999
    Location
    Holland
    Posts
    5

    Re: Reading in a file

    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


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured