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. Type Conversion happens while writing to Logfile in VC++

Type Conversion happens while writing to Logfile in VC++

Scheduled Pinned Locked Moved C / C++ / MFC
7 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.
  • A Offline
    A Offline
    aruzhere
    wrote on last edited by
    #1

    I am trying to output certain int variables to my logfile. But upon viewing the logfile these varuiables are shown in hex. any idea why this happens? ofstream logfile; GetLocalTime(&st); sprintf(logfilename,"Myfilename_%d%02d%02d.log",st.wYear,st.wMonth,st.wDay); logfile.open(logfilename, ios::app); logfile <<"# Time is :: "<

    J L 2 Replies Last reply
    0
    • A aruzhere

      I am trying to output certain int variables to my logfile. But upon viewing the logfile these varuiables are shown in hex. any idea why this happens? ofstream logfile; GetLocalTime(&st); sprintf(logfilename,"Myfilename_%d%02d%02d.log",st.wYear,st.wMonth,st.wDay); logfile.open(logfilename, ios::app); logfile <<"# Time is :: "<

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      I don't know why your stream uses hex format here. But you can set the format: ios_base::fmtflags - C++ Reference[^]. Because you are still using the C library function sprintf for the file name you might use it also for formatting the output. I still prefer this because it is often simpler (e.g. for date and times with leading zeroes).

      1 Reply Last reply
      0
      • A aruzhere

        I am trying to output certain int variables to my logfile. But upon viewing the logfile these varuiables are shown in hex. any idea why this happens? ofstream logfile; GetLocalTime(&st); sprintf(logfilename,"Myfilename_%d%02d%02d.log",st.wYear,st.wMonth,st.wDay); logfile.open(logfilename, ios::app); logfile <<"# Time is :: "<

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I just ran the above code and the values are all in decimal. There must be something else in your code that is causing the issue.

        A 1 Reply Last reply
        0
        • L Lost User

          I just ran the above code and the values are all in decimal. There must be something else in your code that is causing the issue.

          A Offline
          A Offline
          aruzhere
          wrote on last edited by
          #4

          Actually this is only a part of the code. I have int variables declared and those are also displayed in hex in the logfile. will it have something to do with the settings while I build the same in Visual C++?

          L 1 Reply Last reply
          0
          • A aruzhere

            Actually this is only a part of the code. I have int variables declared and those are also displayed in hex in the logfile. will it have something to do with the settings while I build the same in Visual C++?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            No, but somewhere you are setting the stream attributes to display all integers in HEX rather than DEC format.

            A 1 Reply Last reply
            0
            • L Lost User

              No, but somewhere you are setting the stream attributes to display all integers in HEX rather than DEC format.

              A Offline
              A Offline
              aruzhere
              wrote on last edited by
              #6

              Thanks a lot.. There are instances in the code where the stream is set to hex. Upon removal the same works fine. But is there a way without removing hex and set the stream back to display DEC ?

              A 1 Reply Last reply
              0
              • A aruzhere

                Thanks a lot.. There are instances in the code where the stream is set to hex. Upon removal the same works fine. But is there a way without removing hex and set the stream back to display DEC ?

                A Offline
                A Offline
                aruzhere
                wrote on last edited by
                #7

                Found out the way to do that without actually removing Hex. Used <

                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