Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. scanning until the EOF

scanning until the EOF

Scheduled Pinned Locked Moved C / C++ / MFC
iosdotnetquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Desmo16
    wrote on last edited by
    #1

    Hi all, I have the following code: // CODE STARTS HERE // int i,j; std::fstream f_load; char appoggio[20]; // carica il nan oppure il valore numerico CString percorso; CFileDialog fd(TRUE, NULL, percorso, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY); fd.m_pOFN->lpstrTitle = "Carica file di osservazioni"; if (fd.DoModal() == IDOK) { percorso = fd.GetPathName(); UpdateData(false); f_load.open(percorso,std::ios::in); int contatore = 0; do{ f_load>>appoggio; contatore++; } while(f_load!=EOF); } // CODE ENDS HERE // but there's something wrong in the while condition. Which is the right while condition to scan the file until its end ? Thanx in advance, Desmo16.

    W 1 Reply Last reply
    0
    • D Desmo16

      Hi all, I have the following code: // CODE STARTS HERE // int i,j; std::fstream f_load; char appoggio[20]; // carica il nan oppure il valore numerico CString percorso; CFileDialog fd(TRUE, NULL, percorso, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY); fd.m_pOFN->lpstrTitle = "Carica file di osservazioni"; if (fd.DoModal() == IDOK) { percorso = fd.GetPathName(); UpdateData(false); f_load.open(percorso,std::ios::in); int contatore = 0; do{ f_load>>appoggio; contatore++; } while(f_load!=EOF); } // CODE ENDS HERE // but there's something wrong in the while condition. Which is the right while condition to scan the file until its end ? Thanx in advance, Desmo16.

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #2

      In your loop, you are checking if the EOF has been reached at the end of the loop, but the pointer has already been increased causing your code not to go through the loop for the final time. You should test before entering the loop, ie while (f_load != EOF) { // do your loop }

      D 1 Reply Last reply
      0
      • W Waldermort

        In your loop, you are checking if the EOF has been reached at the end of the loop, but the pointer has already been increased causing your code not to go through the loop for the final time. You should test before entering the loop, ie while (f_load != EOF) { // do your loop }

        D Offline
        D Offline
        Desmo16
        wrote on last edited by
        #3

        I don't think it's that the matter, because the compiler tells me it cannot convert an int (the EOF) into a std::fstream (the f_load)

        W 1 Reply Last reply
        0
        • D Desmo16

          I don't think it's that the matter, because the compiler tells me it cannot convert an int (the EOF) into a std::fstream (the f_load)

          W Offline
          W Offline
          Waldermort
          wrote on last edited by
          #4

          Sorry, been a while since I used it. It think it should be while (!f_load.eof() ) { }

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups