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. output file in VC++

output file in VC++

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
3 Posts 3 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.
  • M Offline
    M Offline
    mr2003
    wrote on last edited by
    #1

    Hi, I am trying to get a few parameters in an output file. i have included fsteam.h, and iostream.h my code is: ofstream out("output.txt"); CMyDoc* pDoc = GetDocument(); out<<"12454 "; out<X_Position<<"\n"; out<<"y: "; out<Y_Position<<"\n"; out<<"z: "; out<Z_Position<<"\n"; the code makes the output file, but its always empty,, any siggestions? Ehsan Behboudi

    H A 2 Replies Last reply
    0
    • M mr2003

      Hi, I am trying to get a few parameters in an output file. i have included fsteam.h, and iostream.h my code is: ofstream out("output.txt"); CMyDoc* pDoc = GetDocument(); out<<"12454 "; out<X_Position<<"\n"; out<<"y: "; out<Y_Position<<"\n"; out<<"z: "; out<Z_Position<<"\n"; the code makes the output file, but its always empty,, any siggestions? Ehsan Behboudi

      H Offline
      H Offline
      Hosam Aly Mahmoud
      wrote on last edited by
      #2
      1. When is the file empty? Do you check while your program is running or afterwards? 2) Make sure you have out.close(); after you finish. This is to make sure everything is output on the file.

      Hosam Aly Mahmoud

      1 Reply Last reply
      0
      • M mr2003

        Hi, I am trying to get a few parameters in an output file. i have included fsteam.h, and iostream.h my code is: ofstream out("output.txt"); CMyDoc* pDoc = GetDocument(); out<<"12454 "; out<X_Position<<"\n"; out<<"y: "; out<Y_Position<<"\n"; out<<"z: "; out<Z_Position<<"\n"; the code makes the output file, but its always empty,, any siggestions? Ehsan Behboudi

        A Offline
        A Offline
        Abin
        wrote on last edited by
        #3

        First, the contents may be output to some file else if you use relative path like that, you better use absolute path to make sure the destination file is exactly which you expected. So type this instead: ofstream out("C:\\output.txt");. Second, you need to exam the stream first to make sure the destination file is ready to be written, so add this line right after you open it: ASSERT(out != NULL); Third, always close a opened file as soon as you are done with it, add this line at the end: out.close(); I have a strong feeling that your problem was caused by the first issue, you probably will find "output.txt" in your "My Document" folder, lol.

        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